2

我正在尝试自己实现 SM2。我找到了两个来源作为我对这种做法的参考。

第一

第二个

问题1 我很困惑。哪一个是正确的?我不能完全确定 SM2 的正确实现是什么。

问题 2 我尝试关注 FIRST ONE 的博客,以下是我的代码。我做对了吗?帮助真的很感激。

algorithm-sm2
public abstract class SM2_Impl {
    private Double easiness = new Double(2.5);
    private Double consecutiveCorrectAnswers = new Double(0);
    private Double nextDueDate = new Double(0);

    public Double getEasiness() {
        return easiness;
    }
    public void setEasiness(Double easiness) {
        this.easiness = easiness;
    }
    public Double getConsecutiveCorrectAnswers() {
        return consecutiveCorrectAnswers;
    }
    public void setConsecutiveCorrectAnswers(Double consecutiveCorrectAnswers) {
        this.consecutiveCorrectAnswers = consecutiveCorrectAnswers;
    }
    public Double getNextDueDate() {
        return nextDueDate;
    }
    public void setNextDueDate(Double nextDueDate) {
        this.nextDueDate = nextDueDate;
    }

    public void ans(PerformanceRatingEnum performanceRating) {
        performanceRating.getLevel();
        this.easiness +=  -0.8 + 0.28*performanceRating.getLevel() + 0.02*Math.pow(performanceRating.getLevel(), 2);
        if (this.easiness < 1.3) {
            this.easiness = 1.3; // the min val
        }else if (this.easiness > 3) {
            this.easiness = 3.0; // the max val 
        }


        switch(performanceRating) {
        case CORRECT_RESPONSE_03:
        case CORRECT_RESPONSE_04:
        case PERFECT_RESPONSE_05:
            this.consecutiveCorrectAnswers++;
            this.nextDueDate = this.nextDueDate + (6 * Math.pow(this.easiness, this.consecutiveCorrectAnswers - 1));
            break;
        case COMPLETE_BLACKOUT_00:
        case INCORRECT_RESPONSE_01:
        case INCORRECT_RESPONSE_02:
            this.consecutiveCorrectAnswers = 0.0;
            this.nextDueDate = this.nextDueDate + 1;
            break;
        default:
            break;
        }

    }

    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this);
    }

}

问题 3 一旦我得到了这个算法的正确实现,我该如何测试它?如果有人可以建议一个测试场景,那将非常有帮助。

4

0 回答 0