def test9_double_user_response(self): nback = NBackGame(n_back=1, char_generator=fixed_chars('X')).start() nback.next_char() # Warmup nback.next_char() nback.user_match() nback.user_match() nback.user_no_match() assert_score(nback, correct_match=1)
def test72_user_stop_after_response(self): nback = NBackGame(n_back=1, char_generator=fixed_chars('X')).start() # Warmup nback.next_char() # Rounds nback.next_char() nback.user_match() nback.stop() assert_score(nback, 1, 0, 0, 0)
def test54_user_interaction_during_warmup_is_ignored(self): nback = NBackGame(n_back=2, char_generator=fixed_chars("AXCXE")).start() nback.next_char() nback.user_match() assert_score(nback, 0, 0, 0, 0) nback.next_char() nback.user_no_match() assert_score(nback, 0, 0, 0, 0) score_sanity_check(nback)
def test51_user_correct_interaction(self): nback = NBackGame(n_back=2, char_generator=fixed_chars("AXCXE")).start() nback.next_char() nback.next_char() nback.next_char() nback.user_no_match() assert_score(nback, 0, 0, 1, 0) nback.next_char() nback.user_match() assert_score(nback, 1, 0, 1, 0) nback.next_char() nback.user_no_match() assert_score(nback, 1, 0, 2, 0)
def test61_reaction_time(self): nback = NBackGame(n_back=2, char_generator=fixed_chars("X")).start() nback.next_char() nback.next_char() nback.next_char() time.sleep(0.1) nback.user_match() t = nback.reaction_time[MATCH][True].sum self.assert_(0.1 <= t and t <= 0.2) nback.next_char() time.sleep(0.2) nback.user_match() t = nback.reaction_time[MATCH][True].sum self.assert_(0.3 <= t and t <= 0.31) t = nback.reaction_time[MATCH][True].avg self.assert_(0.15 <= t and t <= 0.16)
def test52_user_wrong_interaction(self): nback = NBackGame(n_back=2, char_generator=fixed_chars("AXCXE")).start() nback.next_char() nback.next_char() nback.next_char() nback.user_match() assert_score(nback, 0, 1, 0, 0) nback.next_char() nback.user_no_match() assert_score(nback, 0, 1, 0, 1) nback.next_char() nback.user_match() assert_score(nback, 0, 2, 0, 1) score_sanity_check(nback)
def test71_user_stop_before_response(self): nback = NBackGame(n_back=2, char_generator=fixed_chars('X')).start() # Warmup nback.next_char() nback.next_char() # Rounds nback.next_char() nback.user_match() nback.next_char() nback.stop() assert_score(nback, 1, 0, 0, 0) # NOTE: current_round > sum of responses self.assertEqual(2, nback.current_round) # Continued action does nothing nback.user_match() assert_score(nback, 1, 0, 0, 0) nback.next_char() self.assertEqual(2, nback.current_round) nback.user_match() assert_score(nback, 1, 0, 0, 0)
def testA_callbacks(self): schedule = MagicMock() show_symbol = MagicMock() show_score = MagicMock() nback = NBackGame(n_back=1, char_generator=fixed_chars('AABBCD'), show_symbol=show_symbol, show_score=show_score, schedule=schedule).start() hide_call = call(nback.show_symbol_interval, nback.hide_symbol) next_call = call(nback.next_symbol_interval, nback.next_char) show_symbol.assert_not_called() nback.next_char() show_symbol.assert_called_once_with('A') schedule.assert_has_calls([hide_call, next_call]) nback.next_char() show_symbol.assert_called_with('A') schedule.assert_has_calls([hide_call, next_call] * 2) nback.user_match() show_score.assert_called_once_with(correct_match=1, correct_no_match=0, wrong_match=0, wrong_no_match=0, no_response=0) nback.next_char() show_symbol.assert_called_with('B') schedule.assert_has_calls([hide_call, next_call] * 3) nback.user_no_match() show_score.assert_called_with(correct_match=1, correct_no_match=1, wrong_match=0, wrong_no_match=0, no_response=0) # Display no response as "wrong" nback.next_char() show_symbol.assert_called_with('B') nback.next_char() show_symbol.assert_called_with('C') show_score.assert_called_with(correct_match=1, correct_no_match=1, wrong_match=0, wrong_no_match=0, no_response=1) nback.next_char() show_symbol.assert_called_with('D') show_score.assert_called_with(correct_match=1, correct_no_match=1, wrong_match=0, wrong_no_match=0, no_response=2) nback.user_match() show_score.assert_called_with(correct_match=1, correct_no_match=1, wrong_match=1, wrong_no_match=0, no_response=2)
def test8_nback(self): nback = NBackGame(n_back=1, char_generator=fixed_chars("CCCCDE")).start() nback.next_char() # Warmup nback.next_char() nback.user_match() nback.next_char() nback.user_match() nback.next_char() nback.user_match() nback.next_char() nback.user_no_match() nback.next_char() nback.user_no_match() assert_score(nback, 3, 0, 2, 0) nback = NBackGame(n_back=2, char_generator=fixed_chars("CCCCDE")).start() nback.next_char() # Warmup nback.next_char() # Warmup nback.next_char() nback.user_match() nback.next_char() nback.user_match() nback.next_char() nback.user_no_match() nback.next_char() nback.user_no_match() assert_score(nback, 2, 0, 2, 0) nback = NBackGame(n_back=3, char_generator=fixed_chars("CCCCDE")).start() nback.next_char() # Warmup nback.next_char() # Warmup nback.next_char() # Warmup nback.next_char() nback.user_match() nback.next_char() nback.user_no_match() nback.next_char() nback.user_no_match() assert_score(nback, 1, 0, 2, 0)