def test_select_column(self): np.random.seed(2) random_distribution: [float] = np.random.rand(5) position, random_distribution = Evolution().select_column(random_distribution) self.assertEqual(position, 2) clean_up()
def test_get_session_ids(self): database: Database = Database() database.store_user(Samples.sample_user) database.store_session(Samples.sample_user.user_key, Samples.sample_session) result: [int] = database.get_session_ids(Samples.sample_user.user_key) self.assertEqual(result, [42]) clean_up()
def test_execute2(self): set_up_two_sample_users() result: str = Evolution().execute('user_002') # Assuming that the hightest session stored for # the sample user should be 'session_042'. self.assertEqual(result, 'session_003') clean_up()
def test_execute(self): set_up_training_data() result: str = Evolution().execute('user_001') # Assuming that the hightest session stored for # the sample user should be 'session_042'. self.assertEqual(result, 'session_004') clean_up()
def compute_average_user_performance(self): set_up() normalization: Normalization = Normalization() user_keys: str = Database().get_user_keys() for user_key in user_keys: normalization.calculate_average_performance(user_key) Cluster(1).cluster_users() clean_up()
def test_store_level(self): database: Database = Database() database.store_user(Samples.sample_user) database.store_session('user_042', Samples.sample_session) database.store_level('user_042', 'session_042', Samples.sample_level) level: Level = database.get_level('user_042', 'session_042', Samples.sample_level.key) self.assertEqual(level.to_dict(), Samples.sample_level.to_dict()) clean_up()
def test_get_session_keys(self): database: Database = Database() database.store_user(Samples.sample_user) database.store_session(Samples.sample_user.user_key, Samples.sample_session) result = database.get_session_keys('user_042') expected_result: [str] = ['session_042'] self.assertEqual(result, expected_result) clean_up()
def test_get_performance(self): database: Database = Database() database.store_user(Samples.sample_user) database.store_session(Samples.sample_user.user_key, Samples.sample_session) result: Performance = database.get_performance( Samples.sample_user.user_key, Samples.sample_session.session_key) expected_result: Performance = Samples.sample_session.performance self.assertEqual(result.to_dict(), expected_result.to_dict()) clean_up()
def test_get_session(self): set_up() # Should retrieve an existing session from Firestore. result: Session = Database().get_session( Samples.sample_user.user_key, Samples.sample_session.session_key) timestamp = result.to_dict()['timestamp'] # Defines the expected result. expected_result: Session = Samples.sample_session expected_result.timestamp = timestamp # Expects the result to be equal to a predefined sample session. self.assertEqual(result.to_dict(), expected_result.to_dict()) clean_up()
def test_set_average_performance(self): database: Database = Database() database.store_user(Samples.sample_user) database.store_session(Samples.sample_user.user_key, Samples.sample_session) database.set_average_performance('user_042', Samples.sample_performance) result: Performance = database.get_average_performance('user_042') expected_result: Performance = Samples.sample_performance self.assertEqual(result.to_dict(), Samples.sample_performance.to_dict()) clean_up()
def test_calculate_user_score(self): # Sets up a test environment. set_up() # Calculates the user score for a sample user. result: int = Normalization().calculate_user_score( Samples.sample_user.user_key) # Expects the user score to be 100. expected_result: int = 100 # Assets whether the result is equals the expected result. self.assertEqual(result, expected_result) # Removes the test environment. clean_up()
def test_create_DataFrame(self): set_up() df = Normalization().create_DataFrame('user_042') result = df.loc[['user_042:session_042']].values excepted_result = [[1., 1., 1., 0., 600., 45., 15., 80]] self.assertEqual(result[0][0], excepted_result[0][0]) self.assertEqual(result[0][1], excepted_result[0][1]) self.assertEqual(result[0][2], excepted_result[0][2]) self.assertEqual(result[0][3], excepted_result[0][3]) self.assertEqual(result[0][4], excepted_result[0][4]) self.assertEqual(result[0][5], excepted_result[0][5]) self.assertEqual(result[0][6], excepted_result[0][6]) self.assertEqual(result[0][7], excepted_result[0][7]) clean_up()
def test_calculate_average_performance(self): set_up() df = Normalization().calculate_average_performance('user_042') result = df.loc[['user_042']].values excepted_result = [[1., 1., 1., 0., 600., 45., 15., 80]] self.assertEqual(result[0][0], excepted_result[0][0]) self.assertEqual(result[0][1], excepted_result[0][1]) self.assertEqual(result[0][2], excepted_result[0][2]) self.assertEqual(result[0][3], excepted_result[0][3]) self.assertEqual(result[0][4], excepted_result[0][4]) self.assertEqual(result[0][5], excepted_result[0][5]) self.assertEqual(result[0][6], excepted_result[0][6]) self.assertEqual(result[0][7], excepted_result[0][7]) clean_up()
def test_normalize_performance(self): # Sets up a test environment. set_up() # df = Normalization().normalize_performance() result = df.loc[['user_042']].values excepted_result = [[1., 1., 1., 0., 1., 1., 1., 1.]] self.assertEqual(result[0][0], excepted_result[0][0]) self.assertEqual(result[0][1], excepted_result[0][1]) self.assertEqual(result[0][2], excepted_result[0][2]) self.assertEqual(result[0][3], excepted_result[0][3]) self.assertEqual(result[0][4], excepted_result[0][4]) self.assertEqual(result[0][5], excepted_result[0][5]) self.assertEqual(result[0][6], excepted_result[0][6]) self.assertEqual(result[0][7], excepted_result[0][7]) clean_up()
def test_setup(self): clean_up() self.assertEqual(True, True)