iT邦幫忙

2023 iThome 鐵人賽

DAY 28
0
自我挑戰組

2023年度學習分享系列 第 28

規劃Normal Anki Note測試案例

  • 分享至 

  • xImage
  •  

文章未來將更新於:
https://kevinyay945.com/golang-project-design/anki-support/design-normal-anki-note-operator/

接下來我們要實做Normal Anki Note的測試案例
在我們的卡片中,預計希望的流程如下

  1. 日文單字轉換成聲音檔
  2. 日文單字造句
  3. 造好的句子產生聲音檔
  4. 產生好的檔案存回anki,並
  5. 將tag從todo變成done

當預計的實做流程出來後,測試的內容就可以像下面的內容一樣寫出來

func (t *OperatorSuite) Test_normal_operator() {  
    fields := map[string]FieldData{  
       "Expression":                 {Value: "test expression value"},  
       "Meaning":                    {Value: "test meaning value"},  
       "Reading":                    {Value: "test reading value"},  
       "Japanese-ToSound":           {Value: "test japanese to sound value"},  
       "JapaneseSentence":           {Value: "test japanese hiragana sentence value"},  
       "JapaneseSentence-ToSound":   {Value: "test japanese sentence to sound value"},  
       "JapaneseSentence-ToChinese": {Value: "test japanese sentence to chinese value"},  
       "Japanese-Note":              {Value: "test japanese note value"},  
       "Japanese-ToChineseNote":     {Value: "test japanese to chinese note value"},  
       "Answer-Note":                {Value: "test answer note value"},  
    }  
    note := Note{  
       Id:        123,  
       ModelName: "Japanese (recognition&recall)",  
       Fields:    fields,  
       Tags:      []string{"anki-helper-vocabulary-todo"},  
    }  
    japaneseSentence := "test japanese sentence"  
    rememberVocabularyList := []string{"vocabulary1", "vocabulary2"}  
    expressionVoicePath := "expression/file/path.mp3"  
    japaneseSentenceVoicePath := "japanese/sentence/file/path.mp3"  
    // expression to Japanese-ToSound by text to speech  
    t.mockTextToSpeecher.EXPECT().  
       GetJapaneseSound(fields["Expression"].Value).  
       Return(expressionVoicePath, nil)  
    // expression to JapaneseSentence and JapaneseSentence-ToChinese and JapaneseSentence-ToSound.Name by gpt  
    t.mockGPTer.EXPECT().  
       MakeJapaneseSentence(fields["Expression"].Value, fields["Meaning"].Value, rememberVocabularyList).  
       Return(japaneseSentence, fields["JapaneseSentence"].Value, fields["JapaneseSentence-ToChinese"].Value, nil)  
    // JapaneseSentence to JapaneseSentence-ToSound by text to speech  
    t.mockTextToSpeecher.EXPECT().  
       GetJapaneseSound(japaneseSentence).  
       Return(japaneseSentenceVoicePath, nil)  
    // ankier update note by id with expect data  
    t.mockAnkier.EXPECT().  
       UpdateNoteById(note.Id, note, []Audio{  
          {  
             Path:     expressionVoicePath,  
             Filename: fmt.Sprintf("[Sound:%s.mp3]", fields["Meaning"].Value),  
             Fields:   []string{"Japanese-ToSound"},  
          },  
          {  
             Path:     japaneseSentenceVoicePath,  
             Filename: fmt.Sprintf("[Sound:%s.mp3]", japaneseSentence),  
             Fields:   []string{"JapaneseSentence-ToSound"},  
          },  
       }).  
       Return(nil)  
    // delete todo tag in anki card  
    t.mockAnkier.EXPECT().DeleteNoteTagFromNoteId(note.Id, AnkiTodoTagName).Return(nil)  
    // add done tag at anki card  
    t.mockAnkier.EXPECT().AddNoteTagFromNoteId(note.Id, AnkiDoneTagName).Return(nil)  
  
    operator, err := t.generator.GetByNote(Note{  
       Id:        note.Id,  
       ModelName: note.ModelName,  
       Fields: map[string]FieldData{  
          "Expression":                 fields["Expression"],  
          "Meaning":                    fields["Meaning"],  
          "Reading":                    fields["Reading"],  
          "Japanese-ToSound":           {Value: ""},  
          "JapaneseSentence":           {Value: ""},  
          "JapaneseSentence-ToSound":   {Value: ""},  
          "JapaneseSentence-ToChinese": {Value: ""},  
          "Japanese-Note":              {Value: "test japanese note value"},  
          "Japanese-ToChineseNote":     {Value: "test japanese to chinese note value"},  
          "Answer-Note":                {Value: "test answer note value"},  
       },  
       Tags: []string{"anki-helper-vocabulary-todo"},  
    })  
    t.NoError(err)  
    err = operator.Do()  
    t.NoError(err)  
}

以下是這次的code
https://github.com/kevinyay945/anki-support/blob/1125c8d34ad677a780c3da592d14a5163c7358ff/domain/operator_test.go

下一篇就可以開始implement需要的內容


上一篇
規劃及實做anki-operator-generator功能
下一篇
完成Normal Anki Note實際的功能
系列文
2023年度學習分享30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言