Exemplo n.º 1
0
    def test_09_remove_word_from_vocab(self):
        vocab = Vocab.Vocab(word_dict)
        self.assertTrue('electromechanical' in vocab.getVocabDict().keys())
        self.assertTrue(vocab.remove_word_from_vocab('electromechanical'))
        self.assertFalse('electromechanical' in vocab.getVocabDict().keys())

        self.assertFalse(vocab.remove_word_from_vocab('asfg'))
        self.assertTrue(vocab.remove_word_from_vocab('afternoon'))
        self.assertFalse('afternoon' in vocab.getVocabDict().keys())

        vocab.add_word_to_vocab('afternoon')

        shutil.copyfile('StudyPlan/Vocab.pkl', 'StudyPlan/Vocab_copy.pkl')
        self.assertTrue(os.path.exists('StudyPlan/Vocab_copy.pkl'))
        vocab_copy = Vocab.Vocab(word_dict)
        self.assertEqual(vocab_copy.init_method, Vocab.LOAD_EXISTING_VOCAB)
        word = random.choice(list(vocab.getVocabDict().keys()))
        for key in vocab.getVocabDict().keys():
            if key != word:
                self.assertTrue(vocab_copy.remove_word_from_vocab(key))
        self.assertFalse(vocab_copy.remove_word_from_vocab(word))
        self.assertEqual(len(vocab_copy.getVocabDict()), 1)

        shutil.copyfile('StudyPlan/Vocab_copy.pkl', 'StudyPlan/Vocab.pkl')
        os.remove('StudyPlan/Vocab_copy.pkl')
        self.assertFalse(os.path.exists('StudyPlan/Vocab_copy.pkl'))
Exemplo n.º 2
0
    def test_02_init_vocab(self):
        if os.path.exists('StudyPlan/Vocab.pkl'):
            os.remove('StudyPlan/Vocab.pkl')

        vocab = Vocab.Vocab(word_dict)
        self.assertEqual(vocab.init_method, Vocab.CREATE_NEW_VOCAB)
        self.assertEqual(len(vocab.getVocabDict()), len(word_dict.word_list))

        vocab.saveVocab()
        vocab = Vocab.Vocab(word_dict)
        self.assertEqual(vocab.init_method, Vocab.LOAD_EXISTING_VOCAB)
        self.assertEqual(len(vocab.getVocabDict()), len(word_dict.word_list))
Exemplo n.º 3
0
    def test_08_add_word_to_vocab(self):
        vocab = Vocab.Vocab(word_dict)
        word = random.choice(list(vocab.getVocabDict().keys()))
        vocab.updateFamiliarity(word, 1)
        vocab.add_word_to_vocab(word)
        self.assertEqual(vocab.getFamiliarity(word), 0)

        self.assertFalse(vocab.add_word_to_vocab('asdfg'))

        self.assertFalse('electromechanical' in vocab.getVocabDict().keys())
        vocab.add_word_to_vocab('electromechanical')
        self.assertTrue(
            'electromechanical' in vocab.getVocabDict().keys() and vocab.getVocabDict()['electromechanical'] == 0)
        vocab = Vocab.Vocab(word_dict)
        self.assertTrue(
            'electromechanical' in vocab.getVocabDict().keys() and vocab.getVocabDict()['electromechanical'] == 0)
Exemplo n.º 4
0
 def __init__(self, WORD_DICT, parent):
     # Get todayList
     # self.today_list = ["test"]
     self.vocab = Vocab.Vocab(WORD_DICT)
     self.vocab.saveVocab()  # 保存词库
     self.today_list_obj = TodayList.TodayList(self.vocab)
     self.open = True
     if self.today_list_obj.new_user:
         value, ok = QInputDialog.getInt(parent, '学习计划设定',
                                         '请输入每天需要背诵的数量(5-700):', 50, 5, 700,
                                         1)
         if ok:
             self.today_list_obj.plan_for_new_user(value, self.vocab)
         else:
             self.open = False
             return
     self.today_list_dict = self.today_list_obj.getTodayList()
     self.today_list = list(self.today_list_dict.keys())
     self.finished = False
     self.ite = -1
     self.review_list = []
     # self.is_first_round = True
     if self.next_word():
         print('开始背单词')
         if len(self.today_list) > 0:
             self.word_current = self.today_list[self.ite]
         else:
             print("Fail to get recite list for today")
             self.finished = True
     else:  # 今天的任务已经背完了
         QMessageBox.information(parent, '提醒', '你已经背完今天的单词了呢,注意劳逸结合哦~',
                                 QMessageBox.Yes)
         # parent.close()
         self.finished = True
Exemplo n.º 5
0
    def test_05_getFamiliarity(self):
        vocab = Vocab.Vocab(word_dict)
        word = random.choice(list(vocab.getVocabDict().keys()))
        self.assertEqual(vocab.getFamiliarity(word), 0)
        vocab.updateFamiliarity(word, 1)
        self.assertEqual(vocab.getFamiliarity(word), 1)

        word = 'electromechanical'
        self.assertEqual(vocab.getFamiliarity(word), -1)
Exemplo n.º 6
0
 def test_03_getInfo(self):
     vocab = Vocab.Vocab(word_dict)
     word = random.choice(list(vocab.getVocabDict().keys()))
     self.assertEqual(vocab.getInfo(word), word_dict.get_info(word))
     word = 'electromechanical'
     self.assertFalse(word in vocab.getVocabDict().keys())
     self.assertFalse(word in word_dict.word_list)
     self.assertEqual(vocab.getInfo(word), word_dict.get_info(word))
     word = 'asdfgh'
     self.assertEqual(vocab.getInfo(word), WordDict.WORD_NOT_FOUND)
Exemplo n.º 7
0
    def test_13_get_n_word_from_todaylist(self):
        vocab = Vocab.Vocab(word_dict)
        todaylist_obj = TodayList.TodayList(vocab)
        todaylist_dict = todaylist_obj.getTodayList()

        get_list = todaylist_obj.get_n_word_from_todaylist(5)
        self.assertTrue(set(get_list).issubset(set(list(todaylist_dict.keys()))))

        get_list = todaylist_obj.get_n_word_from_todaylist(20)
        self.assertEqual(len(get_list), 0)
Exemplo n.º 8
0
    def test_06_getNewVocabList(self):
        vocab = Vocab.Vocab(word_dict)
        familiarity = [1, 2]
        for key in vocab.getVocabDict().keys():
            vocab.updateFamiliarity(key, random.choice(familiarity))

        new_word_list = random.sample(list(vocab.getVocabDict().keys()), 10)
        for word in new_word_list:
            vocab.updateFamiliarity(word, 0)
        self.assertTrue(set(new_word_list).issuperset(set(vocab.getNewVocabList())) and set(
            set(vocab.getNewVocabList())).issuperset(new_word_list))
Exemplo n.º 9
0
 def test_10_get_n_word_from_familiarVocab(self):
     vocab = Vocab.Vocab(word_dict)
     set_familiar_word_list = random.sample(list(vocab.getVocabDict().keys()), 50)
     for word in set_familiar_word_list:
         vocab.updateFamiliarity(word, 2)
     get_list = vocab.get_n_word_from_familiarVocab(10)
     self.assertIsInstance(get_list, list)
     self.assertEqual(len(get_list), 10)
     self.assertTrue(set(get_list).issubset(set(set_familiar_word_list)))
     get_list = vocab.get_n_word_from_familiarVocab(60)
     self.assertEqual(len(get_list), 0)
     get_list = vocab.get_n_word_from_familiarVocab(-1)
     self.assertEqual(len(get_list), 0)
Exemplo n.º 10
0
    def test_14_time_concept(self):
        vocab = Vocab.Vocab(word_dict)
        todaylist_obj = TodayList.TodayList(vocab)
        todaylist_obj.plan_for_new_user(50, vocab)
        todaylist_obj.save_todaylist()
        pre_todaylist = list(todaylist_obj.getTodayList().keys())

        todaylist_obj = TodayList.TodayList(vocab)
        curr_todaylist = list(todaylist_obj.getTodayList().keys())
        self.assertTrue(pre_todaylist == curr_todaylist)

        pre_todaylist = curr_todaylist
        todaylist_obj.change_date(datetime.date.today() + datetime.timedelta(days=1))
        todaylist_obj.save_todaylist()
        todaylist_obj = TodayList.TodayList(vocab)
        curr_todaylist = list(todaylist_obj.getTodayList().keys())
        self.assertFalse(pre_todaylist == curr_todaylist)
Exemplo n.º 11
0
    def test_12_add_word_to_todaylist(self):
        vocab = Vocab.Vocab(word_dict)
        todaylist_obj = TodayList.TodayList(vocab)
        todaylist_obj.plan_for_new_user(10, vocab)
        todaylist_dict = todaylist_obj.getTodayList()

        word = random.choice(list(todaylist_dict.keys()))
        self.assertFalse(todaylist_obj.add_word_to_todaylist(word, vocab))

        while True:
            word = random.choice(list(vocab.getVocabDict().keys()))
            if word not in todaylist_dict.keys():
                break
        self.assertTrue(todaylist_obj.add_word_to_todaylist(word, vocab))
        self.assertEqual(len(todaylist_obj.getTodayList()), 11)

        todaylist_obj = TodayList.TodayList(vocab)
        self.assertEqual(len(todaylist_obj.getTodayList()), 11)

        self.assertFalse(todaylist_obj.add_word_to_todaylist('dsddsds', vocab))
Exemplo n.º 12
0
from StudyPlan import TodayList
from StudyPlan import Vocab
import random

# 先生成词汇表vocab
vocab = Vocab.Vocab()

# 根据词汇表生成今日计划todayList
todayList = TodayList.TodayList(vocab).getTodayList()
print(todayList)  # 打印todayList检查是否符合要求

# 测试用代码,确认vocab中词汇的熟悉程度可以更新
familiarity = [0, 1, 2]
for key in vocab.getVocabDict().keys():
    vocab.updateFamiliarity(key, random.choice(familiarity))  # 给每个词随机赋予熟悉程度
vocab.display()
vocab.saveVocab()
Exemplo n.º 13
0
    def __init__(self, WORD_DICT):
        super(SettingGUI, self).__init__()
        self.setupUi(self)

        # Init study setting
        self.vocab = Vocab.Vocab(WORD_DICT)
        self.vocab.saveVocab()  # 保存词库
        self.today_list_obj = TodayList.TodayList(self.vocab)
        self.open = True

        if self.today_list_obj.new_user:
            value, ok = QInputDialog.getInt(self, '学习计划设定',
                                            '请输入每天需要背诵的数量(5-700):', 50, 5, 700,
                                            1)
            if ok:
                self.today_list_obj.plan_for_new_user(value, self.vocab)
                self.word_num_today = value
                self.today_list_obj.save_todaylist()
            else:
                self.word_num_today = 50  # 默认值为50
                self.open = False
                return
        else:
            self.word_num_today = self.today_list_obj.get_stated_todaylist_length(
            )

        self.textBrowser.setText(str(self.word_num_today))  # 显示今日词数
        self.textBrowser.setAutoFillBackground(True)
        self.listWidget.setAutoFillBackground(True)
        # self.listWidget_2.setAutoFillBackground(True)

        self.vocab_dict = self.vocab.getVocabDict()
        _translate = QCoreApplication.translate
        ite = 0
        # print(len(self.vocab_dict))
        for word in self.vocab_dict:
            if self.vocab_dict[word] == 0:
                continue
            # print(word)
            # self.listWidget.addItem(word)
            if self.vocab_dict[word] == 1:
                self.listWidget.addItem(word + '    未掌握')
                item = self.listWidget.item(ite)
                # item.setText(_translate("MainWindow", str(word)))
                item.setBackground(QtGui.QColor(0, 255, 0, 40))
                item.setSizeHint(QSize(350, 30))
                item.setTextAlignment(Qt.AlignCenter)
                # self.listWidget_2.addItem('未掌握')
                # item = self.listWidget_2.item(ite)
                # # item.setText(_translate("MainWindow", '未掌握'))
                # item.setBackground(QtGui.QColor(0, 255, 0, 40))
                # item.setSizeHint(QSize(350, 30))
            else:
                self.listWidget.addItem(word + '    已掌握')
                item = self.listWidget.item(ite)
                # item.setText(_translate("MainWindow", str(word)))
                item.setBackground(QtGui.QColor(0, 255, 0, 127))
                item.setSizeHint(QSize(350, 30))
                item.setTextAlignment(Qt.AlignCenter)
                # self.listWidget_2.addItem('已掌握')
                # item = self.listWidget_2.item(ite)
                # # item.setText(_translate("MainWindow", '未掌握'))
                # item.setBackground(QtGui.QColor(0, 255, 0, 127))
                # item.setSizeHint(QSize(350, 30))
            ite += 1
Exemplo n.º 14
0
 def test_01_saveVocab(self):
     if os.path.exists('StudyPlan/Vocab.pkl'):
         os.remove('StudyPlan/Vocab.pkl')
     vocab = Vocab.Vocab(word_dict)
     vocab.saveVocab()
     self.assertTrue(os.path.exists('StudyPlan/Vocab.pkl'))
Exemplo n.º 15
0
    def test_11_init_todaylist(self):
        if os.path.exists('StudyPlan/TodayList.pkl'):
            os.remove('StudyPlan/TodayList.pkl')

        vocab = Vocab.Vocab(word_dict)
        todaylist_obj = TodayList.TodayList(vocab)
        self.assertTrue(todaylist_obj.new_user)
        todaylist_obj.plan_for_new_user(20, vocab)
        todaylist_dict = todaylist_obj.getTodayList()
        self.assertEqual(len(todaylist_dict), 20)

        all_value_0_in_todaylist = True
        for k in todaylist_dict:
            if not (todaylist_dict[k] == 0):
                all_value_0_in_todaylist = False
                break
        self.assertTrue(all_value_0_in_todaylist)

        all_familiarity_0_in_todaylist = True
        for k in todaylist_dict:
            if not (vocab.getFamiliarity(k) == 0):
                all_familiarity_0_in_todaylist = False
                break
        self.assertTrue(all_familiarity_0_in_todaylist)

        for k in vocab.getVocabDict().keys():
            vocab.updateFamiliarity(k, 1)
        todaylist_obj.plan_for_new_user(20, vocab)
        todaylist_dict = todaylist_obj.getTodayList()
        all_familiarity_1_in_todaylist = True
        for k in todaylist_dict:
            if not (vocab.getFamiliarity(k) == 1):
                all_familiarity_1_in_todaylist = False
                break
        self.assertTrue(all_familiarity_1_in_todaylist)

        for k in vocab.getVocabDict().keys():
            vocab.updateFamiliarity(k, 2)
        todaylist_obj.plan_for_new_user(20, vocab)
        todaylist_dict = todaylist_obj.getTodayList()
        all_familiarity_2_in_todaylist = True
        for k in todaylist_dict:
            if not (vocab.getFamiliarity(k) == 2):
                all_familiarity_2_in_todaylist = False
                break
        self.assertTrue(all_familiarity_2_in_todaylist)

        new_num = unfamiliar_num = 0
        for k in list(vocab.getVocabDict().keys())[:100]:
            vocab.updateFamiliarity(k, 0)
        for k in list(vocab.getVocabDict().keys())[200:400]:
            vocab.updateFamiliarity(k, 1)
        todaylist_obj.plan_for_new_user(20, vocab)
        todaylist_dict = todaylist_obj.getTodayList()
        for k in todaylist_dict:
            if vocab.getFamiliarity(k) == 0:
                new_num += 1
            if vocab.getFamiliarity(k) == 1:
                unfamiliar_num += 1
        self.assertEqual(new_num, 12)
        self.assertEqual(unfamiliar_num, 8)
Exemplo n.º 16
0
 def test_07_word_is_valid(self):
     vocab = Vocab.Vocab(word_dict)
     self.assertTrue(vocab.word_is_valid('afternoon'))
     self.assertTrue(vocab.word_is_valid('tribology'))
     self.assertFalse(vocab.word_is_valid('asdfg'))