-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathis_test_lessons.py
178 lines (142 loc) · 8.56 KB
/
is_test_lessons.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# -*- coding: utf-8 -*-
"""
Created on Wed Mar 22 11:10:24 2023
@author: Zoe
"""
import is_question_generator as qgen
import is_lesson_options as lo
import itertools
import random as rd
from inspect import signature
#This top section of functions are just called inside the actual test function.
#The tester doesn't need to use these functions.
#But you do want to update the all_randomiser_params dictionary
#when you create a new lesson.
def get_randomiser_params(lesson, vocab):
"""Returns a dictionary of the randomiser parameters with their range of values.
Update the dictionary in here when a new lesson is created."""
if vocab == None:
range_vocab = 0
else:
range_vocab = range(len(vocab))
range_pronouns = range(7)
range_pronouns_names = range(8)
range_boolean = [True, False]
all_randomiser_params = {"give_get" : {"subject_num" : range_pronouns_names,
"object_num" : range_pronouns_names,
"gift_num" : range_vocab,
"give_get_num" : range(2)},
"possession_aig" : {"subject_num" : range_pronouns,
"object_num" : range_vocab},
"gender" : {"vocab_num" : range_vocab},
"numbers" : {"num" : range(100)},
"plurals" : {"vocab_num" : range_vocab},
"learn_nouns" : {"vocab_num" : range_vocab},
"preferences" : {"subject_num" : range_pronouns,
"object_num" : range_vocab,
"tense" : range(2),
"pos_neg" : range(2),
"likepref" : range(2)},
"verb_tenses" : {"verb_num" : range_vocab,
"pers_num" : range_pronouns},
"professions_annan" : {"person_num" : range_pronouns,
"profession_num" : range(len(qgen.professions))},
"emphasis_adjectives" : {"person_num" : range_pronouns,
"modifier_choice" : range(len(qgen.adj_modifiers)),
"adj_num" : range_vocab},
"possession_mo" : {"whose_num" : range_pronouns,
"where_num" : range(3),
"what_num" : range_vocab},
"where_from" : {"person_num" : range_pronouns,
"where_num" : range_vocab},
"where_in" : {"person_num" : range_pronouns,
"where_num" : range_vocab,
"article_switch" : range(2)},
"comparisons" : {"comparison_choice" : range(len(qgen.similes))},
"comparatives_superlatives" : {"subject_num" : range_vocab,
"object_num" : range_vocab,
"adj_num" : range(len(qgen.adjectives))},
"time" : {"hrs_num" : range(0, 24),
"mins_num" : range(0, 60, 5)},
"which_season" : {"month_num" : range(12),
"use_prep" : range_boolean},
"which_month" : {"holiday_num" : range(len(qgen.list_holidays)),
"month_num" : range(12),
"use_prep" : range_boolean,
"pers_num" : range_pronouns},
"going_to" : {"person_num" : range_pronouns,
"where_num" : range_vocab},
"give_to" : {"subject_num" : range_pronouns,
"object_num" : range_pronouns,
"gift_num" : range_vocab,
"give_get_num" : range(2),
"article_switch" : range_boolean},
"get_from" : {"subject_num" : range_pronouns,
"object_num" : range_pronouns,
"gift_num" : range_vocab,
"give_get_num" : range(2),
"article_switch" : range_boolean}
}
return all_randomiser_params[lesson.__name__]
def get_user_params(lesson, vocab):
"""Returns a dictionary of user parameters and their possible values"""
all_lesson_params = [x for x in signature(lesson).parameters]
user_params = dict()
for each in all_lesson_params:
if each in lo.user_menu_options:
user_params[each] = [option[0] for option in lo.user_menu_options[each]]
if "max_num" in all_lesson_params:
user_params["max_num"] = [100]
return user_params
def generate_params(lesson, param_type, vocab):
"""Creates a generator object of each possible combination of values
for the user/randomiser parameters"""
if param_type == "randomiser":
params = get_randomiser_params(lesson, vocab)
else:
params = get_user_params(lesson, vocab)
param_names = params.keys()
ranges = [r for r in params.values()]
for values in itertools.product(*ranges):
yield dict(zip(param_names, values))
def list_params(lesson, param_type, vocab):
"""Creates a list of all possible combinations of values
for the user/randomiser parameters"""
return [combination for combination in generate_params(lesson,
param_type,
vocab)]
#-------------- Below is the function you use for testing
def test(lesson, fulltest = False):
"""Generates question, prompt, solution-list
fulltest == True: all possible combinations of parameters
fulltest == False: a random combination of parameters, as many times as specified
'lesson' must be the function, e.g. qgen.give_get;
vocab_sample must be a vocabulary file (imported with csvr)"""
if "vocab_sample" in signature(lesson).parameters:
vocab_sample_str = input("Name the vocab list (must be a csvr dict): ")
vocab = eval(vocab_sample_str)
if lo.check_vocab(lesson.__name__, vocab) == False:
return
else:
vocab = None
user_params = list_params(lesson, "user", vocab)
if fulltest == True:
for user_combination in user_params:
for randomiser_combination in list_params(lesson, "randomiser", vocab):
if vocab == None:
print(lesson(**user_combination,
testvalues = randomiser_combination))
else:
print(lesson(**user_combination,
vocab_sample = vocab,
testvalues = randomiser_combination))
else:
repeat_num = input("Number of tests? ")
for x in range(int(repeat_num)):
if vocab == None:
print(lesson(**rd.choice(user_params),
testvalues = None))
else:
print(lesson(**rd.choice(user_params),
vocab_sample = vocab,
testvalues = None))