2

I'm trying to implement SM2 by myself. I found two sources as my references for this practice.

FIRST ONE

SECOND ONE

Question 1 I got confused. Which one is the right one? I can't quite put my fingers on what's the correct implementation of SM2.

Question 2 I try to follow the FIRST ONE's blog and the following is my code. Did I do it right? Help really appreciated.

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);
    }

}

Question 3 How can I test it once I got the right implementation of this algorithm? It would be really helpful if someone can suggest a test scenario.

Sheng-yu Tsai
  • 41
  • 1
  • 7

0 Answers0