def test_1x1x1(self, mock_file_to_list, mock_print, mock_shuffle): mock_file_to_list.side_effect = [["a"], ["b"]] mock_shuffle.side_effect = [("a", "b")] filename1 = "file_one" filename2 = "file_two" generate_pairs.generate_pairs(filename1, filename2, 1) self.assertEqual(2, mock_file_to_list.call_count) mock_file_to_list.assert_has_calls([call(filename1), call(filename2)]) self.assertEqual(1, mock_shuffle.call_count) mock_shuffle.assert_has_calls([call([("a", "b")])]) self.assertEqual(1, mock_print.call_count) mock_print.assert_has_calls([call("a,b")])
def test_2x2x1(self, mock_file_to_list, mock_print, mock_shuffle): mock_file_to_list.side_effect = [["a", "b"], ["c", "d"]] mock_shuffle.side_effect = swap_first_two filename1 = "file_one" filename2 = "file_two" generate_pairs.generate_pairs(filename1, filename2, 1) self.assertEqual(2, mock_file_to_list.call_count) mock_file_to_list.assert_has_calls([call(filename1), call(filename2)]) self.assertEqual(1, mock_shuffle.call_count) # Note: mock does not save the parameter, so it too is affected by side-effects mock_shuffle.assert_has_calls([call([("a", "d"), ("a", "c"), ("b", "c"), ("b", "d")])]) self.assertEqual(4, mock_print.call_count) mock_print.assert_has_calls([call("a,d"), call("a,c"), call("b,c"), call("b,d")])
def test_generate_pairs_zero(): solution = [[0, 0]] assert generate_pairs(0) == solution
def test_generate_pairs_two(): solution = [[0, 0], [0, 1], [0, 2], [1, 1], [1, 2], [2, 2]] assert generate_pairs(2) == solution