def test_get_points_different_size_stat( self ): """ Tests if a list of statistics have back the right points. The list and the expected points are the following: (0,)->6 (1,)->3 (0, 0)->8 (0, 1)->4 (1, 0)->5 (1, 1)->2 (0, 0, 0)->10 (0, 0, 1)->6 (0, 1, 0)->6 (0, 1, 1)->2 (1, 0, 0)->7 (1, 0, 1)->4 (1, 1, 0)->4 (1, 1, 1)->1 """ # Mock the __ini__ with patch.object(FilteredDictionary, "__init__", lambda x: None): myFilteredDictionary=FilteredDictionary() myFilteredDictionary.base_language="hungarian" myFilteredDictionary.learning_language="swedish" myFilteredDictionary.recent_stat_list={i:list(i) for i in list(itertools.product([0,1], repeat=1)) + list(itertools.product([0,1], repeat=2)) + list(itertools.product([0,1], repeat=3))} myFilteredDictionary.word_dict={"1":('v', ['AAA'], 'aaa', '') } expected_list=[6,3,8,4,5,2,10,6,6,2,7,4,4,1] # run with all statuses -> result zipped with the expected valus -> pairs substracted from each other -> sum -> it must be 0 self.assertEqual( sum( [ j[0]-j[1] for j in zip( [myFilteredDictionary.get_points(i) for i in myFilteredDictionary.recent_stat_list], expected_list) ] ), 0 )
def test_get_next_random_record_only_one_good_answer( self ): """ Tests if there is about same chance to get the words which had not got good answer yet """ # Mock the __ini__ with patch.object(FilteredDictionary, "__init__", lambda x: None): myFilteredDictionary=FilteredDictionary() myFilteredDictionary.base_language="hungarian" myFilteredDictionary.learning_language="swedish" myFilteredDictionary.recent_stat_list={ "1":[0,0,0], "2":[0,0,0], "3":[0,1,0], "4":[0,0,0], } myFilteredDictionary.word_dict={ "1":('v', ['AAA'], 'aaa', ''), "2":('v', ['BBB'], 'bbb', ''), "3":('v', ['CCC'], 'ccc', ''), "4":('v', ['DDD'], 'ddd', '') } loop=300000 result=Counter([myFilteredDictionary.get_next_random_record().base_word for i in range(loop)]) self.assertAlmostEqual( loop/3, result['aaa'], delta=600) self.assertAlmostEqual( loop/3, result['bbb'], delta=600) self.assertAlmostEqual( 0.0, result['ccc'], delta=0) self.assertAlmostEqual( loop/3, result['ddd'], delta=600)
def test_get_random_id_wighted_chance( self ): """ Tests if the chance to get the words are proportional to the point (weight) what they have. """ # Mock the __ini__ with patch.object(FilteredDictionary, "__init__", lambda x: None): myFilteredDictionary=FilteredDictionary() myFilteredDictionary.base_language="hungarian" myFilteredDictionary.learning_language="swedish" myFilteredDictionary.recent_stat_list={ "a": [1,1,1], # 1 point (weight) "b": [0,1,1], # 2 points (weight) } myFilteredDictionary.word_dict={ "1":('v', ['AAA'], 'aaa', ''), "2":('v', ['BBB'], 'aaa', '') } result=Counter( [myFilteredDictionary.get_random_id(myFilteredDictionary.recent_stat_list) for i in range(40000)] ) self.assertAlmostEqual( result["b"] / result["a"], 2.0, delta=0.08)
def test_get_next_has_good_answer( self ): """ Tests if the chance to get the words are proportional to the point (weight) what they have. It means: 10%/20%/30%/40% in sequence """ # Mock the __ini__ with patch.object(FilteredDictionary, "__init__", lambda x: None): myFilteredDictionary=FilteredDictionary() myFilteredDictionary.base_language="hungarian" myFilteredDictionary.learning_language="swedish" myFilteredDictionary.recent_stat_list={ "1":[1,1,1], # 1 point => 1/20 probability "2":[0,1,1], # 2 points => 2/20 probability "3":[1,0,1], # 4 points => 4/20 probability "4":[0,1,0], # 6 points => 6/20 probability "5":[1,0,0], # 7 points => 7/20 probability } myFilteredDictionary.word_dict={ "1":('v', ['AAA'], 'aaa', ''), "2":('v', ['BBB'], 'bbb', ''), "3":('v', ['CCC'], 'ccc', ''), "4":('v', ['DDD'], 'ddd', ''), "5":('v', ['EEE'], 'eee', '') } loop=40000 result=Counter([myFilteredDictionary.get_next_random_record().base_word for i in range(loop)]) self.assertAlmostEqual(result['aaa']/loop, 1/20, delta=0.01) self.assertAlmostEqual(result['bbb']/loop, 2/20, delta=0.01) self.assertAlmostEqual(result['ccc']/loop, 4/20, delta=0.01) self.assertAlmostEqual(result['ddd']/loop, 6/20, delta=0.01) self.assertAlmostEqual(result['eee']/loop, 7/20, delta=0.01)