def test_single_arg_equal_calls(self): input_single = "" input_sequence = [""] self.assertEqual(fit_transform(input_single), fit_transform(input_sequence))
def test_single_arg_equal_calls(): input_single = "" input_sequence = [""] assert fit_transform(input_single) == fit_transform( input_sequence ), "same single argument in iterable and as is yields different results"
def test_similar_args(): exp = [ ('a', [1]), ('a', [1]), ] res_args = one_hot_encoder.fit_transform('a', 'a') res_list = one_hot_encoder.fit_transform(['a', 'a']) assert exp == res_args assert exp == res_list
def test_similar_args(self): exp = [ ('a', [1]), ('a', [1]), ] res_args = one_hot_encoder.fit_transform('a', 'a') res_list = one_hot_encoder.fit_transform(['a', 'a']) self.assertEqual(exp, res_args) self.assertEqual(exp, res_list)
def test_args(): exp = [ ('a', [0, 0, 1]), ('b', [0, 1, 0]), ('c', [1, 0, 0]), ] res_args = one_hot_encoder.fit_transform('a', 'b', 'c') res_list = one_hot_encoder.fit_transform(['a', 'b', 'c']) assert exp == res_args assert exp == res_list
def test_args(self): exp = [ ('a', [0, 0, 1]), ('b', [0, 1, 0]), ('c', [1, 0, 0]), ] res_args = one_hot_encoder.fit_transform('a', 'b', 'c') res_list = one_hot_encoder.fit_transform(['a', 'b', 'c']) self.assertEqual(exp, res_args) self.assertEqual(exp, res_list)
def test_with_multiple_repeats(self): test_word = ['first', 'second', 'first', 'second', 'first'] answer_test_words = one_hot_encoder.fit_transform(test_word) correct_answer = [('first', [0, 1]), ('second', [1, 0]), ('first', [0, 1]), ('second', [1, 0]), ('first', [0, 1])] self.assertEqual(correct_answer, answer_test_words)
def test_sequential_numeration(self): input_sequence = list("abcd") actual = [t[1] for t in fit_transform(input_sequence)] self.assertIn([0, 0, 1, 0], actual) self.assertNotIn([1, 0, 0, 0, 0], actual)
def test_one_city(): cities = ['Moscow'] actual = one_hot_encoder.fit_transform(cities) expected = [ ('Moscow', [1]), ] assert actual == expected
def test_arg(): input = one_hot_encoder.fit_transform(['N', 'o']) res = [ ('N', [0, 1]), ('o', [1, 0]), ] assert input == res
def test_ok_repeated_liberty(): cities = {'Liberty', 'Liberty', 'Liberty'} actual = one_hot_encoder.fit_transform(cities) expected = [ ('Liberty', [1]), ] assert actual == expected
def test_str(): """Аргумент функции - строки.""" assert fit_transform("a", "b", "c") == [ ("a", [0, 0, 1]), ("b", [0, 1, 0]), ("c", [1, 0, 0]), ]
def test_simple_list(): test_list = ['abc', 'bca', 'abc'] actual = fit_transform(test_list) expected = [('abc', [0, 1]), ('bca', [1, 0]), ('abc', [0, 1])] assert actual == expected
def test_list(): """Аргумент функции - список.""" assert fit_transform(["a", "b", "c"]) == [ ("a", [0, 0, 1]), ("b", [0, 1, 0]), ("c", [1, 0, 0]), ]
def test_with_one_repeat(): test_words = ['first', 'second', 'first', 'third', 'fourth'] answer_test_words = one_hot_encoder.fit_transform(test_words) correct_answer = [('first', [0, 0, 0, 1]), ('second', [0, 0, 1, 0]), ('first', [0, 0, 0, 1]), ('third', [0, 1, 0, 0]), ('fourth', [1, 0, 0, 0])] assert answer_test_words == correct_answer
def test_list_str(): assert fit_transform(['Moscow', 'New York', 'Moscow', 'London']) == [ ('Moscow', [0, 0, 1]), ('New York', [0, 1, 0]), ('Moscow', [0, 0, 1]), ('London', [1, 0, 0]), ]
def test_single_repeated(): expected = [("8", [1]), ("8", [1]), ("8", [1])] input_sequence = ["8"] * 3 actual = fit_transform(input_sequence) assert (expected == actual ), "multiple entrances of same string give different encodings"
def test_ok_for_sequence_without_copy(): cities = ['Moscow', 'Liberty'] actual = one_hot_encoder.fit_transform(cities) expected = [ ('Moscow', [0, 1]), ('Liberty', [1, 0]), ] assert actual == expected
def test_args_str(): """Тест поведения функции, если входные аргументы - строки.""" assert fit_transform('Moscow', 'New York', 'Moscow', 'London') == [ ('Moscow', [0, 0, 1]), ('New York', [0, 1, 0]), ('Moscow', [0, 0, 1]), ('London', [1, 0, 0]), ]
def test_list_int(): """Тест поведения функции, если входной аргумент - list[int].""" assert fit_transform([1, 2, 3, 3]) == [ (1, [0, 0, 1]), (2, [0, 1, 0]), (3, [1, 0, 0]), (3, [1, 0, 0]), ]
def test_ok_two_same_cities(self): cities = ['Moscow', 'Moscow'] actual = one_hot_encoder.fit_transform(cities) expected = [ ('Moscow', [1]), ('Moscow', [1]), ] self.assertEqual(actual, expected)
def test_pytest_cities_without_copy(): cities = ['Moscow', 'New York', 'Moscow'] expected = [ ('Moscow', [0, 1]), ('New York', [1, 0]), ('Moscow', [0, 1]), ] assert one_hot_encoder.fit_transform(cities) == expected
def test_unique_city(): cities = ['Moscow', 'New York'] actual = one_hot_encoder.fit_transform(cities) expected = [ ('Moscow', [0, 1]), ('New York', [1, 0]), ] assert actual == expected
def test_ok_two_diff_cities(): cities = ['Moscow', 'Perm'] actual = one_hot_encoder.fit_transform(cities) expected = [ ('Moscow', [0, 1]), ('Perm', [1, 0]), ] assert actual == expected
def test_with_one_repeat(self): test_words = ['first', 'second', 'first', 'third', 'fourth'] answer_test_words = one_hot_encoder.fit_transform(test_words) correct_answer = [('first', [0, 0, 0, 1]), ('second', [0, 0, 1, 0]), ('first', [0, 0, 0, 1]), ('third', [0, 1, 0, 0]), ('fourth', [1, 0, 0, 0])] self.assertIn(correct_answer[2], answer_test_words) self.assertEqual(correct_answer, answer_test_words)
def test_list_float(): """Тест поведения функции, если входные аргументы типа float.""" assert fit_transform([1.0, 2.5, 3.3, 3.7]) == [ (1.0, [0, 0, 0, 1]), (2.5, [0, 0, 1, 0]), (3.3, [0, 1, 0, 0]), (3.7, [1, 0, 0, 0]), ]
def test_wrong_str(self): cities = 'ab' exp_transformed_cities = [ ('a', [0, 1]), ('b', [0, 1]), ] transformed_cities = fit_transform(*cities) self.assertNotEqual(transformed_cities, exp_transformed_cities)
def test_wrong_str(): cities = 'ab' exp_transformed_cities = [ ('a', [0, 1]), ('b', [0, 1]), ] transformed_cities = fit_transform(*cities) assert transformed_cities != exp_transformed_cities
def test_list_str(): """Тест поведения функции, если входным аргументом является список.""" assert fit_transform(['Moscow', 'New York', 'Moscow', 'London']) == [ ('Moscow', [0, 0, 1]), ('New York', [0, 1, 0]), ('Moscow', [0, 0, 1]), ('London', [1, 0, 0]), ]
def test_ok_two_diff_cities(self): cities = ['Moscow', 'Perm'] actual = one_hot_encoder.fit_transform(cities) expected = [ ('Moscow', [0, 1]), ('Perm', [1, 0]), ] self.assertEqual(actual, expected)