def test_fullReport_known(self): patterns = [("389125467", "25467389"), ("837419265", "92658374"), ("12345", "2345")] for pattern, expected in patterns: ill = indexedlinkedlist.IndexedList(pattern) self.assertEqual([int(c) for c in expected], d23_cupgame.report(ill))
def test_insertAfterValue_partiallyPatterned_20(self): """ Mirror the slice functions in a partially patterned list. :return: """ pattern = "389125467" size = 20 insertionPoint = 13 l = indexedlinkedlist.IndexedList(pattern, size) expectedValues = [int(c) for c in pattern] expectedValues.extend([i + 1 for i in range(len(pattern), size)]) # print(expectedValues) self.assertEqual(expectedValues, [val for val in l], "List init Mismatch: Test Aborted.") slice = l.popSlice(1, 4) listSlice = [i for i in slice] expectedSlice = expectedValues[1:4] # print(expectedSlice) self.assertEqual(expectedSlice, listSlice, "Popped slice Mismatch: Test Aborted.") expectedValues = expectedValues[:1] + expectedValues[4:] # print(expectedValues) self.assertEqual(expectedValues, [val for val in l], "Remainder List Mismatch: Test Aborted.") index = expectedValues.index(insertionPoint) expectedValues = expectedValues[:index + 1] + expectedSlice + expectedValues[ index + 1:] # print(expectedValues) l.insertAfterValue(insertionPoint, slice) self.assertEqual(expectedValues, [val for val in l])
def test_insertAfterValue_unpatterned_calculated(self): """ Mirror the slice functions in a regular list. :return: """ size = 10 l = indexedlinkedlist.IndexedList(size=size) sortedValues = [i for i in range(1, size + 1)] self.assertEqual(sortedValues, [val for val in l], "List init Mismatch: Test Aborted.") slice = l.popSlice(1, 4) listSlice = [i for i in slice] expectedSlice = sortedValues[1:4] self.assertEqual(expectedSlice, listSlice, "Popped slice Mismatch: Test Aborted.") expectedValues = sortedValues[:1] + sortedValues[4:] self.assertEqual(expectedValues, [val for val in l], "Remainder List Mismatch: Test Aborted.") index = expectedValues.index(7) expectedValues = expectedValues[:index + 1] + expectedSlice + expectedValues[ index + 1:] l.insertAfterValue(7, slice) self.assertEqual(expectedValues, [val for val in l])
def test_popSlice_sliceContainsHead(self): l = indexedlinkedlist.IndexedList(size=6) slice = l.popSlice(4, 8) poppedList = [i for i in slice] remainingList = [i for i in l] self.assertEqual([5, 6, 1, 2], poppedList) self.assertEqual([4, 3], remainingList)
def test_iter_unpatterned_perItem(self): size = 6 l = indexedlinkedlist.IndexedList(size=size) expectedValue = 1 for value in l: self.assertEqual(expectedValue, value, expectedValue) expectedValue += 1
def test_insertAfterValue_fullyPatterned(self): """ Mirror the slice functions in a fully patterned list. :return: """ pattern = "389125467" insertionPoint = 7 l = indexedlinkedlist.IndexedList(pattern) expectedValues = [int(c) for c in pattern] listValues = [val for val in l] # print(expectedValues) self.assertEqual(expectedValues, [val for val in l], "List init Mismatch: Test Aborted.") slice = l.popSlice(1, 4) listSlice = [i for i in slice] expectedSlice = expectedValues[1:4] # print(expectedSlice) self.assertEqual(expectedSlice, listSlice, "Popped slice Mismatch: Test Aborted.") expectedValues = expectedValues[:1] + expectedValues[4:] # print(expectedValues) self.assertEqual(expectedValues, [val for val in l], "Remainder List Mismatch: Test Aborted.") index = expectedValues.index(insertionPoint) expectedValues = expectedValues[:index + 1] + expectedSlice + expectedValues[ index + 1:] # print(expectedValues) l.insertAfterValue(insertionPoint, slice) self.assertEqual(expectedValues, [val for val in l])
def playGame(input, iterations, fullReport=True, size=None): circle = indexedlinkedlist.IndexedList(input, size) for i in range(iterations): move(circle) return report(circle, fullReport)
def test_iter_partiallyPatterned_20(self): pattern = "389125467" size = 20 l = indexedlinkedlist.IndexedList(pattern, size) expectedValues = [int(c) for c in pattern] expectedValues.extend([i + 1 for i in range(len(pattern), size)]) listValues = [val for val in l] self.assertEqual(expectedValues, listValues)
def test_popSlice_checkLengthOfSlice_byInspection(self): ill = indexedlinkedlist.IndexedList(size=5) slice = ill.popSlice(1, 4) item = slice.nextItem length = 1 while item is not None and item is not slice: item = item.nextItem length += 1 self.assertEqual(3, length)
def test_partialReport_known(self): patterns = [("389125467", "25467389"), ("837419265", "92658374"), ("12345", "2345")] for pattern, expected in patterns: ill = indexedlinkedlist.IndexedList(pattern) self.assertEqual( int(expected[0]) * int(expected[1]), d23_cupgame.report(ill, full=False))
def test_indexing_partiallyPatterned_20(self): pattern = "389125467" size = 20 l = indexedlinkedlist.IndexedList(pattern, size) for i in range(len(pattern)): # print(i, end=': ') self.assertEqual(int(pattern[i]), l[i], "Index = {}".format(i)) for i in range(len(pattern), size): # print(i, end=': ') self.assertEqual(i + 1, l[i], "Index = {}".format(i))
def test_move_sequential(self): pattern = "389125467" expecteds = [ "289154673", "546789132", "891346725", "467913258", "136792584", "936725841", "258367419", "674158392", "574183926", "837419265" ] ill = indexedlinkedlist.IndexedList(pattern) for e in expecteds: d23_cupgame.move(ill) self.assertEqual([int(c) for c in e], [val for val in ill])
def test_insertAfterValue_unpatterned_fixed(self): size = 7 l = indexedlinkedlist.IndexedList(size=size) sortedValues = [1, 2, 3, 4, 5, 6, 7] self.assertEqual(sortedValues, [val for val in l], "List init Mismatch: Test Aborted.") slice = l.popSlice(1, 4) listSlice = [i for i in slice] expectedSlice = [2, 3, 4] self.assertEqual(expectedSlice, listSlice, "Popped slice Mismatch: Test Aborted.") expectedValues = [1, 5, 6, 7] self.assertEqual(expectedValues, [val for val in l], "Remainder List Mismatch: Test Aborted.") expectedValues = [1, 5, 6, 2, 3, 4, 7] l.insertAfterValue(6, slice) self.assertEqual(expectedValues, [val for val in l])
def test_len_insertAfterValue_unpatterned_calculated(self): """ Mirror the slice functions in a regular list. :return: """ size = 10 insertionPoint = 8 ill = indexedlinkedlist.IndexedList(size=size) self.assertEqual(size, len(ill), "List init Mismatch: Test Aborted.") slice = ill.popSlice(1, 4) listSlice = [i for i in slice] self.assertEqual(3, len(listSlice), "Popped slice Mismatch: Test Aborted.") self.assertEqual(size - 3, len(ill), "Remainder List Mismatch: Test Aborted.") ill.insertAfterValue(insertionPoint, slice) self.assertEqual(size, len(ill))
def test_len_removeSliceReAdd_fullyPatterned(self): """ Mirror the slice functions in a fully patterned list. :return: """ pattern = "389125467" insertionPoint = 7 ill = indexedlinkedlist.IndexedList(pattern) self.assertEqual(len(pattern), len(ill), "List init Mismatch: Test Aborted.") slice = ill.popSlice(1, 4) listSlice = [i for i in slice] self.assertEqual(3, len(listSlice), "Popped slice Mismatch: Test Aborted.") self.assertEqual( len(pattern) - 3, len(ill), "Remainder List Mismatch: Test Aborted.") ill.insertAfterValue(insertionPoint, slice) self.assertEqual(len(pattern), len(ill))
def test_len_insertAfterValue_partiallyPatterned_20(self): """ Mirror the slice functions in a partially patterned list. :return: """ pattern = "389125467" size = 20 insertionPoint = 13 ill = indexedlinkedlist.IndexedList(pattern, size) self.assertEqual(size, len(ill), "List init Mismatch: Test Aborted.") slice = ill.popSlice(1, 4) listSlice = [i for i in slice] self.assertEqual(3, len(listSlice), "Popped slice Mismatch: Test Aborted.") self.assertEqual(size - 3, len(ill), "Remainder List Mismatch: Test Aborted.") ill.insertAfterValue(insertionPoint, slice) self.assertEqual(size, len(ill))
def test_move_8(self): pattern = "258367419" l = indexedlinkedlist.IndexedList(pattern) d23_cupgame.move(l) self.assertEqual([int(c) for c in "674158392"], [val for val in l])
def test_rotate_listSizePlusOne(self): l = indexedlinkedlist.IndexedList(size=7) l.rotate(8) self.assertEqual([2, 3, 4, 5, 6, 7, 1], [val for val in l])
def test_rotate_listSize(self): l = indexedlinkedlist.IndexedList(size=7) l.rotate(7) self.assertEqual([1, 2, 3, 4, 5, 6, 7], [val for val in l])
def test_rotate_default(self): l = indexedlinkedlist.IndexedList(size=7) l.rotate(-1) self.assertEqual([7, 1, 2, 3, 4, 5, 6], [val for val in l])
def test_popSlice_contains(self): l = indexedlinkedlist.IndexedList(size=5) slice = l.popSlice(1, 4) poppedList = [i for i in slice] self.assertEqual([2, 3, 4], poppedList)
def test_move_4(self): pattern = "891346725" l = indexedlinkedlist.IndexedList(pattern) d23_cupgame.move(l) self.assertEqual([int(c) for c in "467913258"], [val for val in l])
def test_popSlice_checkLengthOfSlice_byLenFunction(self): ill = indexedlinkedlist.IndexedList(size=5) slice = ill.popSlice(1, 4) self.assertEqual(3, len(slice))
def test_popSlice_checkLengthOfList(self): l = indexedlinkedlist.IndexedList(size=5) self.assertEqual(5, len(l)) slice = l.popSlice(1, 4) self.assertEqual(2, len(l))
def test_popSlice_isPopped(self): l = indexedlinkedlist.IndexedList(size=5) slice = l.popSlice(1, 4) self.assertEqual(1, l[0]) self.assertEqual(5, l[1])
def test_move_6(self): pattern = "136792584" l = indexedlinkedlist.IndexedList(pattern) d23_cupgame.move(l) self.assertEqual([int(c) for c in "936725841"], [val for val in l])
def test_indexing_fullPatterned_9(self): l = indexedlinkedlist.IndexedList("389125467") self.assertEqual(3, l[9])
def test_move_10(self): pattern = "574183926" l = indexedlinkedlist.IndexedList(pattern) d23_cupgame.move(l) self.assertEqual([int(c) for c in "837419265"], [val for val in l])
def test_popSlice_checkLengthOfSlice_byListConversion(self): ill = indexedlinkedlist.IndexedList(size=5) slice = ill.popSlice(1, 4) self.assertEqual(3, len([val for val in slice]))
def test_indexing_unpatterned_5(self): l = indexedlinkedlist.IndexedList(size=5) self.assertEqual(1, l[5])