diff --git a/src/test suite.asm b/src/test suite.asm new file mode 100644 index 0000000..6c0b166 --- /dev/null +++ b/src/test suite.asm @@ -0,0 +1,988 @@ +############################################################################################# +# Merge Sort Test Suite # +# # +# Padraic Edgington 28 Oct, 2015 # +# # +# # +# v. 1 Initial release (It might work.) # +# v. 1.1 It works now, still not much here though. # +# v. 1.2 Added some bad data to test for. # +############################################################################################# + +main: addi $sp, $sp, -4 # Make space for $ra on stack + sw $ra, 0 ($sp) # Store the return address on the stack + +############################################################################################# +# Functionality Tests # + li $v0, 4 + la $a0, t1 + syscall +############################################################################################# + # Test #1 + # An empty list. + ####################################################################### + jal setSavedRegisters + la $a0, d1 # List + jal Merge_Sort + + move $a0, $v0 # Result + la $a1, s1 # Expected result + li $a2, 1 # Test #1 + la $a3, c1 # Description of test + jal assertEqual_List # Check for equality. + .data +d1: .word 0 +s1: .word 0 +c1: .asciiz "Testing the termination condition." + .text + + + # Test #2 + # A list with a single element. + ####################################################################### + jal setSavedRegisters + la $a0, d2 # List + jal Merge_Sort + + move $a0, $v0 # Result + la $a1, s2 # Expected result + li $a2, 2 # Test #2 + la $a3, c2 # Description of test + jal assertEqual_List # Check for equality. + .data +d2: .word 1, 1 +s2: .word 1, 1 +c2: .asciiz "Testing the termination condition." + .text + + + # Test #3 + # A presorted list with two elements. + ####################################################################### + jal setSavedRegisters + la $a0, d3 # List + jal Merge_Sort + + move $a0, $v0 # Result + la $a1, s3 # Expected result + li $a2, 3 # Test #3 + la $a3, c3 # Description of test + jal assertEqual_List # Check for equality. + .data +d3: .word 2, 1, 2 +s3: .word 2, 1, 2 +c3: .asciiz "Testing basic recursion using a presorted list." + .text + + + # Test #4 + # An unsorted list with two elements. + ####################################################################### + jal setSavedRegisters + la $a0, d4 # List + jal Merge_Sort + + move $a0, $v0 # Result + la $a1, s4 # Expected result + li $a2, 4 # Test #4 + la $a3, c4 # Description of test + jal assertEqual_List # Check for equality. + .data +d4: .word 2, 2, 1 +s4: .word 2, 1, 2 +c4: .asciiz "Testing ability to compare and reorganize the list." + .text + + + # Test #5 + # A presorted list with 5 elements. + ####################################################################### + jal setSavedRegisters + la $a0, d5 # List + jal Merge_Sort + + move $a0, $v0 # Result + la $a1, s5 # Expected result + li $a2, 5 # Test #5 + la $a3, c5 # Description of test + jal assertEqual_List # Check for equality. + .data +d5: .word 5, -3, -2, -1, 0, 1 +s5: .word 5, -3, -2, -1, 0, 1 +c5: .asciiz "Testing recursion with a presorted list." + .text + + + # Test #6 + # An unsorted list with 11 elements. + ####################################################################### + jal setSavedRegisters + la $a0, d6 # List + jal Merge_Sort + + move $a0, $v0 # Result + la $a1, s6 # Expected result + li $a2, 6 # Test #6 + la $a3, c6 # Description of test + jal assertEqual_List # Check for equality. + .data +d6: .word 11, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5 +s6: .word 11, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5 +c6: .asciiz "Short test." + .text + + # Test #7 + # An unsorted list with 50 elements. + jal setSavedRegisters + la $a0, d7 # List + jal Merge_Sort + + move $a0, $v0 # Result + la $a1, s7 # Expected result + li $a2, 7 # Test #7 + la $a3, c7 # Description of test + jal assertEqual_List # Check for equality. + .data +d7: .word 50, 1814341432, -129067002, 68975759, -291331526, -1004356440, 1456713640, -1615972061, 1474854998, 1075183649, 1973777137, 1284242539, 1119756979, -564013532, 389270527, 417297909, -1380804849, 796587841, -863186325, -1296080597, 1443303665, -330620144, 79389506, -1845135790, -1952860637, 1152055114, -796342803, 553382855, 1196282153, 952142895, -1263019282, 1215246406, -1857401524, -1400977217, -2134689516, -1360635599, 1590720249, -1180613297, -542881441, 1653018756, -1074333496, 2146835483, 1279889896, -1873165225, 200459515, 1212245646, 120122926, -488930743, 415834868, 917284314, 1659576833 +s7: .word 50, -2134689516, -1952860637, -1873165225, -1857401524, -1845135790, -1615972061, -1400977217, -1380804849, -1360635599, -1296080597, -1263019282, -1180613297, -1074333496, -1004356440, -863186325, -796342803, -564013532, -542881441, -488930743, -330620144, -291331526, -129067002, 68975759, 79389506, 120122926, 200459515, 389270527, 415834868, 417297909, 553382855, 796587841, 917284314, 952142895, 1075183649, 1119756979, 1152055114, 1196282153, 1212245646, 1215246406, 1279889896, 1284242539, 1443303665, 1456713640, 1474854998, 1590720249, 1653018756, 1659576833, 1814341432, 1973777137, 2146835483 +c7: .asciiz "Medium test." + .text + + + # Test #8 + # An unsorted list with 1024 elements. + ####################################################################### + jal setSavedRegisters + la $a0, d8 # List + jal Merge_Sort + + move $a0, $v0 # Result + la $a1, s8 # Expected result + li $a2, 8 # Test #8 + la $a3, c8 # Description of test + jal assertEqual_List # Check for equality + .data +d8: .word 1024, -784561419, -4033406, -2103011957, 564929546, 152112058, -32343104, -1607568878, 268830360, 1763988213, 578848526, -82152831, -698389847, -148054226, 950422373, 1908844540, 1452005258, -1265546186, 142578355, 1583761762, 1816660702, -1764468408, 1339965000, -420557374, -1250732387, 1962617717, -1970678116, 310281170, 981016607, 908202274, -923029575, -2050117803, 675678546, -1098145198, 1040470160, -1235355279, -1239567166, -1468137014, -1410429159, -1204379600, -2032732228, -788672402, 2080537739, 1636797501, -2034216, 2037904983, -1829272678, 1249751105, 30084166, 112252926, 1333718913, 880414402, 334691897, -957338815, 17084333, 1070118630, 2111543209, 1129029736, -1525250702, 198749844, 2123740404, -922850412, 667945179, 1235233343, 1413475797, -1939837674, -1163077982, 1361507145, -875156952, -541104792, -1651446937, 854777807, -1471294401, 1563137348, -1516896003, -934734716, 1294979669, -1627964709, -199527317, 806669383, -577153258, 1071953403, -664107659, 771361748, 1131385020, -597354781, -30122380, 1364828348, -1431073050, 1109863328, -1228030105, -1516284181, -305353343, 859474495, 167522376, 1094225558, 1963711766, 1257324636, 1729949323, 125753755, 1068698284, 1761594045, 2106609220, 1033190229, 946183933, 1100436279, 489306665, -1909922140, 658699819, -986949956, -1908969786, 105622857, 1976233741, 1535497010, 314176889, 1247500738, 2138106664, -1537888525, -1861506485, -324060825, 1944201130, -1928630794, -1753427381, -9984361, 224898482, 1457988276, -2106813059, -639848152, 979144237, 1279857832, -1583257133, -201030036, -1995073876, 2121869254, -1789507459, 1847263294, -1320509663, -855163558, 1672773492, 225684598, -1798109909, 611619631, -301944419, -786569280, 1663733971, 758566080, 1653863133, 1701066037, -512083935, -951153580, -1692389630, 629577870, -570873826, 361301181, -1620532319, 1443899064, -190170604, 140754167, -64024298, 447458027, 743917836, -1476652145, 1332110941, 266033703, 308176090, 130356650, -1220769824, -1201575252, 1602712035, 1856287253, -918997051, -1180095233, 370413632, 1435286098, 645351481, 908917276, -1854598858, 1599412846, -1794866567, 790131292, -610445806, -242303360, 1566488352, 295035953, -131524097, -1297041646, 678068969, -627306174, 1273385972, -739172382, 762012623, 1091375739, 1765680277, -56787935, -888376474, -497721040, 388618876, -2134273733, 349961032, 1392360403, -715942206, 604490212, -717143366, -1973504645, -504545241, -1109231355, -2065306710, 1128575466, 884862908, -964210168, -1100799058, 681073659, 800341641, 2006864675, -1675331075, 1577889182, -719811344, -2034850512, -605825418, 1657848984, -1652587065, -1416482732, -1195014216, 468844464, -160603665, -184327456, 1904558184, 1937194892, -1157364805, -651271598, 820242909, -1226594565, -906218373, -59364231, -1679851923, 1555770904, 1520951990, 1047053830, 1663094463, -346502252, 1077597088, -1298022979, -1063992687, 2019388652, 865275198, 2046271241, -1131346666, 269072378, -2041526542, 277763586, 1114595358, -1615150074, 988885471, 922982460, 477046426, 1161679484, -1344875298, 2088879880, -778060795, 1403601752, 1184069822, -763937836, -1253653944, -935793126, 2117925252, 1529768389, 1253051929, 1829668776, -1616200941, 2138924913, -1147667488, 447212163, 1069119222, -503262637, 804904386, -714621884, 1700215583, 904016717, 74539975, 1288558083, 1746888271, 437611701, 781576281, 1166365552, -1728633628, -2110380, -218164816, -326059249, -1237621245, 2074623641, -641329932, 586217310, -1083661067, -1690523318, -991743077, 50953535, 2118693299, 460196852, -939702954, 500727351, 1681849672, 113995187, 1200937601, -1202405434, 312936130, -378884272, -1733255880, -581025596, -2054532388, 637144400, 1946468041, -1070713157, -2052411973, -1769982777, 945834669, -1489768179, 1879274691, -502807176, 37879558, 1205870756, -786947112, -1589233561, -1160753919, -1124889740, 9055729, -2147071544, -506920971, -1872694204, 1228026268, 1275162816, 1385450594, 128490357, 678715088, -1828502893, -1579503555, 420067866, 396072989, 1729810791, -148898453, 389936193, 1010939382, 794725144, 633726173, -727174014, 248988111, 1254549356, 1989964616, 1425389196, -2092608349, -1464553890, -496039914, -852001128, 269966252, -1487320954, 1794971636, 1602977220, 1360381486, 1805272988, 554730358, -35069756, -2126227205, 442942697, -550349675, -727641223, 1232342342, -574756454, 303505483, -761204710, 2136482547, -1481021466, -1243134019, -1464802601, -1137494784, -1108854283, 1063305342, -161123065, 2026873438, 94687021, 42670911, -2089515575, 200274097, -1110624916, 1216199867, 1941807482, 1902652464, -154708641, 1934749011, -1668715901, 1041046135, -1038406980, 2005577300, 367040511, -1732675725, -115710211, 394550850, -580566374, -1198105820, -565170416, -766658183, 1483426196, 821348673, 2057501468, -1153577340, 631596202, -1969315523, -726215668, -1994788460, 257777076, -839291607, -1441058483, 223950412, -1974251708, 250378269, -737133359, 927098460, 315421373, 1957400381, 725633141, -949558012, 1114863797, 1830809043, 1922707457, -509205225, -890215809, -1860134596, 1359584120, 860423718, -1315010767, 888063953, 641814761, 180527770, -978104659, -282007367, 28566252, 1045558574, -163360559, 215968520, 362234156, -2046851360, -1225878084, -891366487, 1812984601, 1768934064, -287381136, 1240758160, 13887765, -780352187, -467593257, -953768581, 1982839159, 2033151304, -11064474, -550776762, 726223056, -389720661, 1875803225, 2030522753, -1472892608, -969485016, 1691268105, -1261100451, 1716543028, 1555574049, -1633873800, 1979855811, -2043033361, 1276056752, -953726028, 1892612984, -2100121242, 486586963, -1802143706, 593230942, 775986230, 1255789287, -1976867694, -1238704216, 158332807, -1843037746, -920831805, 372847709, 1128359579, 373993639, -1875847344, 829613207, -1346756133, -1970801477, 160722663, 1444930279, 765460462, -514471874, 592264489, 316670611, -1952828331, 1439591408, -932749006, -1434064643, 1116562887, -1261288144, 1381679779, 1291533463, 1962666710, -2072593782, 1215751045, -725731232, 1611254503, 1171727980, -1237482812, -1031179632, -1229255020, 781477153, 1881176626, -525924526, 1193467712, -1451062206, -857300938, -2134249692, 419274206, -1527887399, -287603786, 1325555048, -107230662, -228060286, -995217554, 154249616, 1941800223, 1157563946, 705258893, 860757803, 1310317854, 1898329708, -803737723, 312822728, -887965418, 1029352733, -831056944, -1553804259, -1589383484, -1650621661, 683012156, 948328240, -1638100135, 1644147624, -1441091443, 822059867, 753937406, 1604103884, 1756360543, -894320103, -1492201266, -2026776240, -510323352, -1285040059, 394432056, 1840177440, -1643201372, 1205254585, -743485055, -1437029790, -1772458183, -619203230, 1234994787, -835783336, 186529857, 1329960799, -1972569846, 1078548606, 113242357, -1873639790, -988866415, 211880652, 847202265, 1034020264, -1920891810, 755993425, -1820557391, 1885945103, -706940477, -968765865, 747273957, -1122405384, -230363637, 2036147813, -755383808, -1433802439, -991088710, -1909127129, 734771685, 804646316, 1158163327, 2080435695, -1839155934, 2060318701, 1223319334, -1721113565, -953630435, -1087622524, 1654544724, 1227774824, 1779567885, -53541841, -352388339, -1507007387, 90390016, 1235487669, -1889697600, -198069036, 2121644059, -1862960144, -1645960493, 355642145, -296846217, -770385913, 919279000, 789586853, -1829475260, 220701650, -1347743017, 1329892616, -565047795, 1219039514, -1288085107, 281458735, -494467805, -720925871, -2072848945, -187666261, -1607417088, -1034081188, -593107904, -432775934, 1412535194, 1694757183, 772470279, 689128388, -2029412982, -795064354, -1449431846, -1724164328, 1947307958, -267599393, 1910806179, -436077517, -273231844, -216179364, -881935079, -1314913731, -2146157775, 1497338125, 2040525958, -1182905222, -2093086021, -622682281, -1291867832, -485270271, -585790258, -1030040793, 1707537043, 1104985157, -603104876, 1898692192, -1971916202, 736562662, -1994653380, -1194480622, 302436891, 1288467611, 1981059467, -649188660, 1609399619, -876804921, -627124144, 536318325, -1254311942, -1750499365, 424476355, 1601741596, 246832728, -1617679652, -1459544989, 1127786001, 850991343, 2067806155, -528755146, 1001927094, -493898415, -1052658559, 1560596676, 1681618985, -1731968902, -810141774, -1639575300, 1746361319, -744131173, -256224470, 735255465, -340890690, -193597246, -1127955207, 1966689481, 1576556523, 207036082, -1957620627, -890082138, -922772894, -1981194422, 1511011541, -360713537, 152017013, -1989870640, 1003233114, -506785252, -1556883667, -1627648561, -219115784, -375014672, -360279792, 955697805, -573605403, 1892740917, 1925356403, -764321607, 57355987, 500963211, -482704021, -1174264300, -946572856, -1646724691, -1344001736, -1388718424, -99359733, 1976120064, 569029796, -1090072899, 836657553, -41862739, -265443048, 1167446730, -1130710602, 1225943621, 978942573, -407013239, -265273563, -923356158, -1646840114, 341670719, 780349063, 1249088385, -1468980090, 1409751402, -801825753, -1840520301, -1293067754, 894695004, -181373259, -1546847937, -483688834, 337072564, -743698761, -84650843, -1437662580, 1656016234, -1239117103, -220826177, -1592283320, -391447008, -1586857400, 1303194166, 676764765, 1073839, -877942825, 530027902, 664548902, -360777775, 1118172394, 1598501076, 1353136139, -738610529, -443531017, 787984702, -679970639, -1641123954, 350845053, -1754199844, 341795141, -163387738, -1442735993, 347703279, 304754275, -657748938, 1191420956, -44693414, -2077637819, -675954812, -1974577213, 1618600250, 100602741, -332137670, -969128766, -984925721, -2092610062, -1884701596, 1855854724, 1586666379, 1893433651, -82072326, -1216496334, -1289175346, -649870187, -1565636576, 178175659, 1878759843, -681903272, -2059944979, 1229007963, 1217716121, -870323911, 2025817426, -1753656842, -803840256, 834075061, 1476080952, 527792572, -1152350256, 990164480, -756105491, 1101804820, 254185979, 2139277356, -1240989211, -658688726, 1588526078, -1029281238, -1094242830, -989533335, 1714292212, -1400325910, 286242900, -1904272331, 1104137642, 1729447649, -1691820180, 1739535876, -1962641642, -371449326, 975963350, -1248216743, -7827480, -1407540843, -1089593959, -1465847230, 324806067, 1090404329, -1532028337, 2016187695, 188074317, 562585328, 1185556641, -314787445, -1372927629, -1079114007, 946979886, -1472042192, 803185936, 1852384677, -1997811073, -1495479311, 1756284627, -1977229152, 1335401093, 674337096, -1395411499, -298426282, -1280217358, 283034558, -813005160, -484659055, -1569304719, 744192370, -629383828, 571653166, -1113504939, 1782231829, 563269281, 1274600369, -1907996378, 363976120, -1363013866, 614822572, 1661454733, 449226294, -788451052, -867916523, -1674502609, 505585754, -1038417444, 321182353, -404538233, 2030404657, 1191957414, -825930217, 947528907, 578915297, -2139951181, 557136361, 374100253, 1716551606, 1064892772, -2012130787, -2089079861, 735861059, 2088833463, -409973338, 1520195389, -945740715, -178018975, -640777229, -709857813, -2124275262, -190916900, 1431760441, 871040163, -1163745700, -255329330, -1039286699, 1537348827, -20928681, -1528036078, -1214910706, -1867391146, 1698622741, 491269657, -1337815042, -291639973, 1665870563, -1395968411, 350910601, -917055057, 56558544, -1537235170, -1291947718, -1274490812, 1103562767, 266867533, -1056496605, 101050052, -2120825847, -33673252, -916990051, -11934063, 1649319944, -1887424796, 1186270608, 506638155, 853299114, 528018288, -924607106, -862240763, 33304936, 746516661, 864441540, 877624554, 549536499, -1782480423, 1718378202, 1877264374, -387842140, -814665773, 1222420918, -1332554509, 1897386667, 565602854, 870635873, 1837265416, 2093005006, 2069832336, 421542850, 546177829, -557672085, 2022730805, 114777545, 1045010491, 1474827040, 7636789, -368589247, 825140914, -400088528, -2059618476, -85799924, 1363271078, 1633012431, -1690369191, 1475584955, 363136592, -1354973338, -899940975, -1524984797, -1714984874, -917113784, 1926697291, 1309179303, 198769522, 525328917, -1355334909, -455621934, 857890368, 1404166316, 1175685399, -935779659, -1383646612, -963106945, 150684895, 1830720677, -745641994, 1721173678, 1541682359, -567838631, 1378619663, -637321497, 427125659, 87651116, 816648775, 1111028388, -886060490, 1198529401 +s8: .word 1024, -2147071544, -2146157775, -2139951181, -2134273733, -2134249692, -2126227205, -2124275262, -2120825847, -2106813059, -2103011957, -2100121242, -2093086021, -2092610062, -2092608349, -2089515575, -2089079861, -2077637819, -2072848945, -2072593782, -2065306710, -2059944979, -2059618476, -2054532388, -2052411973, -2050117803, -2046851360, -2043033361, -2041526542, -2034850512, -2032732228, -2029412982, -2026776240, -2012130787, -1997811073, -1995073876, -1994788460, -1994653380, -1989870640, -1981194422, -1977229152, -1976867694, -1974577213, -1974251708, -1973504645, -1972569846, -1971916202, -1970801477, -1970678116, -1969315523, -1962641642, -1957620627, -1952828331, -1939837674, -1928630794, -1920891810, -1909922140, -1909127129, -1908969786, -1907996378, -1904272331, -1889697600, -1887424796, -1884701596, -1875847344, -1873639790, -1872694204, -1867391146, -1862960144, -1861506485, -1860134596, -1854598858, -1843037746, -1840520301, -1839155934, -1829475260, -1829272678, -1828502893, -1820557391, -1802143706, -1798109909, -1794866567, -1789507459, -1782480423, -1772458183, -1769982777, -1764468408, -1754199844, -1753656842, -1753427381, -1750499365, -1733255880, -1732675725, -1731968902, -1728633628, -1724164328, -1721113565, -1714984874, -1692389630, -1691820180, -1690523318, -1690369191, -1679851923, -1675331075, -1674502609, -1668715901, -1652587065, -1651446937, -1650621661, -1646840114, -1646724691, -1645960493, -1643201372, -1641123954, -1639575300, -1638100135, -1633873800, -1627964709, -1627648561, -1620532319, -1617679652, -1616200941, -1615150074, -1607568878, -1607417088, -1592283320, -1589383484, -1589233561, -1586857400, -1583257133, -1579503555, -1569304719, -1565636576, -1556883667, -1553804259, -1546847937, -1537888525, -1537235170, -1532028337, -1528036078, -1527887399, -1525250702, -1524984797, -1516896003, -1516284181, -1507007387, -1495479311, -1492201266, -1489768179, -1487320954, -1481021466, -1476652145, -1472892608, -1472042192, -1471294401, -1468980090, -1468137014, -1465847230, -1464802601, -1464553890, -1459544989, -1451062206, -1449431846, -1442735993, -1441091443, -1441058483, -1437662580, -1437029790, -1434064643, -1433802439, -1431073050, -1416482732, -1410429159, -1407540843, -1400325910, -1395968411, -1395411499, -1388718424, -1383646612, -1372927629, -1363013866, -1355334909, -1354973338, -1347743017, -1346756133, -1344875298, -1344001736, -1337815042, -1332554509, -1320509663, -1315010767, -1314913731, -1298022979, -1297041646, -1293067754, -1291947718, -1291867832, -1289175346, -1288085107, -1285040059, -1280217358, -1274490812, -1265546186, -1261288144, -1261100451, -1254311942, -1253653944, -1250732387, -1248216743, -1243134019, -1240989211, -1239567166, -1239117103, -1238704216, -1237621245, -1237482812, -1235355279, -1229255020, -1228030105, -1226594565, -1225878084, -1220769824, -1216496334, -1214910706, -1204379600, -1202405434, -1201575252, -1198105820, -1195014216, -1194480622, -1182905222, -1180095233, -1174264300, -1163745700, -1163077982, -1160753919, -1157364805, -1153577340, -1152350256, -1147667488, -1137494784, -1131346666, -1130710602, -1127955207, -1124889740, -1122405384, -1113504939, -1110624916, -1109231355, -1108854283, -1100799058, -1098145198, -1094242830, -1090072899, -1089593959, -1087622524, -1083661067, -1079114007, -1070713157, -1063992687, -1056496605, -1052658559, -1039286699, -1038417444, -1038406980, -1034081188, -1031179632, -1030040793, -1029281238, -995217554, -991743077, -991088710, -989533335, -988866415, -986949956, -984925721, -978104659, -969485016, -969128766, -968765865, -964210168, -963106945, -957338815, -953768581, -953726028, -953630435, -951153580, -949558012, -946572856, -945740715, -939702954, -935793126, -935779659, -934734716, -932749006, -924607106, -923356158, -923029575, -922850412, -922772894, -920831805, -918997051, -917113784, -917055057, -916990051, -906218373, -899940975, -894320103, -891366487, -890215809, -890082138, -888376474, -887965418, -886060490, -881935079, -877942825, -876804921, -875156952, -870323911, -867916523, -862240763, -857300938, -855163558, -852001128, -839291607, -835783336, -831056944, -825930217, -814665773, -813005160, -810141774, -803840256, -803737723, -801825753, -795064354, -788672402, -788451052, -786947112, -786569280, -784561419, -780352187, -778060795, -770385913, -766658183, -764321607, -763937836, -761204710, -756105491, -755383808, -745641994, -744131173, -743698761, -743485055, -739172382, -738610529, -737133359, -727641223, -727174014, -726215668, -725731232, -720925871, -719811344, -717143366, -715942206, -714621884, -709857813, -706940477, -698389847, -681903272, -679970639, -675954812, -664107659, -658688726, -657748938, -651271598, -649870187, -649188660, -641329932, -640777229, -639848152, -637321497, -629383828, -627306174, -627124144, -622682281, -619203230, -610445806, -605825418, -603104876, -597354781, -593107904, -585790258, -581025596, -580566374, -577153258, -574756454, -573605403, -570873826, -567838631, -565170416, -565047795, -557672085, -550776762, -550349675, -541104792, -528755146, -525924526, -514471874, -512083935, -510323352, -509205225, -506920971, -506785252, -504545241, -503262637, -502807176, -497721040, -496039914, -494467805, -493898415, -485270271, -484659055, -483688834, -482704021, -467593257, -455621934, -443531017, -436077517, -432775934, -420557374, -409973338, -407013239, -404538233, -400088528, -391447008, -389720661, -387842140, -378884272, -375014672, -371449326, -368589247, -360777775, -360713537, -360279792, -352388339, -346502252, -340890690, -332137670, -326059249, -324060825, -314787445, -305353343, -301944419, -298426282, -296846217, -291639973, -287603786, -287381136, -282007367, -273231844, -267599393, -265443048, -265273563, -256224470, -255329330, -242303360, -230363637, -228060286, -220826177, -219115784, -218164816, -216179364, -201030036, -199527317, -198069036, -193597246, -190916900, -190170604, -187666261, -184327456, -181373259, -178018975, -163387738, -163360559, -161123065, -160603665, -154708641, -148898453, -148054226, -131524097, -115710211, -107230662, -99359733, -85799924, -84650843, -82152831, -82072326, -64024298, -59364231, -56787935, -53541841, -44693414, -41862739, -35069756, -33673252, -32343104, -30122380, -20928681, -11934063, -11064474, -9984361, -7827480, -4033406, -2110380, -2034216, 1073839, 7636789, 9055729, 13887765, 17084333, 28566252, 30084166, 33304936, 37879558, 42670911, 50953535, 56558544, 57355987, 74539975, 87651116, 90390016, 94687021, 100602741, 101050052, 105622857, 112252926, 113242357, 113995187, 114777545, 125753755, 128490357, 130356650, 140754167, 142578355, 150684895, 152017013, 152112058, 154249616, 158332807, 160722663, 167522376, 178175659, 180527770, 186529857, 188074317, 198749844, 198769522, 200274097, 207036082, 211880652, 215968520, 220701650, 223950412, 224898482, 225684598, 246832728, 248988111, 250378269, 254185979, 257777076, 266033703, 266867533, 268830360, 269072378, 269966252, 277763586, 281458735, 283034558, 286242900, 295035953, 302436891, 303505483, 304754275, 308176090, 310281170, 312822728, 312936130, 314176889, 315421373, 316670611, 321182353, 324806067, 334691897, 337072564, 341670719, 341795141, 347703279, 349961032, 350845053, 350910601, 355642145, 361301181, 362234156, 363136592, 363976120, 367040511, 370413632, 372847709, 373993639, 374100253, 388618876, 389936193, 394432056, 394550850, 396072989, 419274206, 420067866, 421542850, 424476355, 427125659, 437611701, 442942697, 447212163, 447458027, 449226294, 460196852, 468844464, 477046426, 486586963, 489306665, 491269657, 500727351, 500963211, 505585754, 506638155, 525328917, 527792572, 528018288, 530027902, 536318325, 546177829, 549536499, 554730358, 557136361, 562585328, 563269281, 564929546, 565602854, 569029796, 571653166, 578848526, 578915297, 586217310, 592264489, 593230942, 604490212, 611619631, 614822572, 629577870, 631596202, 633726173, 637144400, 641814761, 645351481, 658699819, 664548902, 667945179, 674337096, 675678546, 676764765, 678068969, 678715088, 681073659, 683012156, 689128388, 705258893, 725633141, 726223056, 734771685, 735255465, 735861059, 736562662, 743917836, 744192370, 746516661, 747273957, 753937406, 755993425, 758566080, 762012623, 765460462, 771361748, 772470279, 775986230, 780349063, 781477153, 781576281, 787984702, 789586853, 790131292, 794725144, 800341641, 803185936, 804646316, 804904386, 806669383, 816648775, 820242909, 821348673, 822059867, 825140914, 829613207, 834075061, 836657553, 847202265, 850991343, 853299114, 854777807, 857890368, 859474495, 860423718, 860757803, 864441540, 865275198, 870635873, 871040163, 877624554, 880414402, 884862908, 888063953, 894695004, 904016717, 908202274, 908917276, 919279000, 922982460, 927098460, 945834669, 946183933, 946979886, 947528907, 948328240, 950422373, 955697805, 975963350, 978942573, 979144237, 981016607, 988885471, 990164480, 1001927094, 1003233114, 1010939382, 1029352733, 1033190229, 1034020264, 1040470160, 1041046135, 1045010491, 1045558574, 1047053830, 1063305342, 1064892772, 1068698284, 1069119222, 1070118630, 1071953403, 1077597088, 1078548606, 1090404329, 1091375739, 1094225558, 1100436279, 1101804820, 1103562767, 1104137642, 1104985157, 1109863328, 1111028388, 1114595358, 1114863797, 1116562887, 1118172394, 1127786001, 1128359579, 1128575466, 1129029736, 1131385020, 1157563946, 1158163327, 1161679484, 1166365552, 1167446730, 1171727980, 1175685399, 1184069822, 1185556641, 1186270608, 1191420956, 1191957414, 1193467712, 1198529401, 1200937601, 1205254585, 1205870756, 1215751045, 1216199867, 1217716121, 1219039514, 1222420918, 1223319334, 1225943621, 1227774824, 1228026268, 1229007963, 1232342342, 1234994787, 1235233343, 1235487669, 1240758160, 1247500738, 1249088385, 1249751105, 1253051929, 1254549356, 1255789287, 1257324636, 1273385972, 1274600369, 1275162816, 1276056752, 1279857832, 1288467611, 1288558083, 1291533463, 1294979669, 1303194166, 1309179303, 1310317854, 1325555048, 1329892616, 1329960799, 1332110941, 1333718913, 1335401093, 1339965000, 1353136139, 1359584120, 1360381486, 1361507145, 1363271078, 1364828348, 1378619663, 1381679779, 1385450594, 1392360403, 1403601752, 1404166316, 1409751402, 1412535194, 1413475797, 1425389196, 1431760441, 1435286098, 1439591408, 1443899064, 1444930279, 1452005258, 1457988276, 1474827040, 1475584955, 1476080952, 1483426196, 1497338125, 1511011541, 1520195389, 1520951990, 1529768389, 1535497010, 1537348827, 1541682359, 1555574049, 1555770904, 1560596676, 1563137348, 1566488352, 1576556523, 1577889182, 1583761762, 1586666379, 1588526078, 1598501076, 1599412846, 1601741596, 1602712035, 1602977220, 1604103884, 1609399619, 1611254503, 1618600250, 1633012431, 1636797501, 1644147624, 1649319944, 1653863133, 1654544724, 1656016234, 1657848984, 1661454733, 1663094463, 1663733971, 1665870563, 1672773492, 1681618985, 1681849672, 1691268105, 1694757183, 1698622741, 1700215583, 1701066037, 1707537043, 1714292212, 1716543028, 1716551606, 1718378202, 1721173678, 1729447649, 1729810791, 1729949323, 1739535876, 1746361319, 1746888271, 1756284627, 1756360543, 1761594045, 1763988213, 1765680277, 1768934064, 1779567885, 1782231829, 1794971636, 1805272988, 1812984601, 1816660702, 1829668776, 1830720677, 1830809043, 1837265416, 1840177440, 1847263294, 1852384677, 1855854724, 1856287253, 1875803225, 1877264374, 1878759843, 1879274691, 1881176626, 1885945103, 1892612984, 1892740917, 1893433651, 1897386667, 1898329708, 1898692192, 1902652464, 1904558184, 1908844540, 1910806179, 1922707457, 1925356403, 1926697291, 1934749011, 1937194892, 1941800223, 1941807482, 1944201130, 1946468041, 1947307958, 1957400381, 1962617717, 1962666710, 1963711766, 1966689481, 1976120064, 1976233741, 1979855811, 1981059467, 1982839159, 1989964616, 2005577300, 2006864675, 2016187695, 2019388652, 2022730805, 2025817426, 2026873438, 2030404657, 2030522753, 2033151304, 2036147813, 2037904983, 2040525958, 2046271241, 2057501468, 2060318701, 2067806155, 2069832336, 2074623641, 2080435695, 2080537739, 2088833463, 2088879880, 2093005006, 2106609220, 2111543209, 2117925252, 2118693299, 2121644059, 2121869254, 2123740404, 2136482547, 2138106664, 2138924913, 2139277356 +c8: .asciiz "Full test." + .text + + +# j Skip_Parameter_Validation_Tests + + + +############################################################################################# +# Error Checking Tests # + li $v0, 4 + la $a0, nl + syscall + la $a0, t2 + syscall +############################################################################################# + # Test #101 + # Try to read from a null array. + ####################################################################### + jal setSavedRegisters + li $a0, 0 # Array + jal Merge_Sort + + move $a0, $v0 # Result + li $a2, 101 # Test #101 + la $a3, c101 # Description of test + jal assertNull # Check for an error. + .data +c101: .asciiz "Null pointer check." + .text + + + # Test #102 + # Array begins outside of memory. + ####################################################################### + jal setSavedRegisters + li $a0, -40 # Array + jal Merge_Sort + + move $a0, $v0 # Result + li $a2, 102 # Test #102 + la $a3, c103 # Description of test + jal assertNull # Check for an error + .data +c103: .asciiz "Array pointer below zero." + .text + .text + + + # Test #103 + # Pointer begins outside of memory + ####################################################################### + jal setSavedRegisters + li $a0, 0x0FCDA890 # Array + jal Merge_Sort + + move $a0, $v0 # Result + li $a2, 103 # Test #103 + la $a3, c105 # Description of test + jal assertNull # Check for an error + .data +c105: .asciiz "Pointer in text range." + .text + + + # Test #104 + # Pointer outside of memory + ####################################################################### + jal setSavedRegisters + li $a0, 0xC0000000 # Array + jal Merge_Sort + + move $a0, $v0 # Result + li $a2, 104 # Test #104 + la $a3, c107 # Description of test + jal assertNull # Check for an error + .data +c107: .asciiz "Pointer too high for dynamic data memory." + .text + + + # Test #105 + # Non-word aligned array + ####################################################################### + jal setSavedRegisters + li $a0, 0x10000002 # Array + jal Merge_Sort + + move $a0, $v0 # Result + li $a2, 105 # Test #105 + la $a3, c109 # Description of test + jal assertNull # Check for an error + .data +c109: .asciiz "Pointer is not word aligned." + .text + + + + # Test #106 + # Non-word aligned array + ####################################################################### + jal setSavedRegisters + li $a0, 0x10000009 # Array + jal Merge_Sort + + move $a0, $v0 # Result + li $a2, 106 # Test #106 + la $a3, c109 # Description of test + jal assertNull # Check for an error + + + # Test #107 + # Non-word aligned array + ####################################################################### + jal setSavedRegisters + li $a0, 0x10000013 # Array + jal Merge_Sort + + move $a0, $v0 # Result + li $a2, 107 # Test #107 + la $a3, c112 # Description of test + jal assertNull # Check for an error + .data +c112: .asciiz "Pointer is not word aligned. (set)" + .text + + + # Test #108 + # Bad array length + ####################################################################### + jal setSavedRegisters + la $a0, d115 # Array + jal Merge_Sort + + move $a0, $v0 # Result + li $a2, 108 # Test #108 + la $a3, c115 # Description of test + jal assertNull # Check for an error + .data +d115: .word -43, 134, 654 +c115: .asciiz "Negative array length." + .text + + + # Test #110 + # Array extends outside of memory + ####################################################################### + jal setSavedRegisters + la $a0, d119 # Array + jal Merge_Sort + + move $a0, $v0 # Result + li $a2, 110 # Test #110 + la $a3, c119 # Description of test + jal assertNull # Check for an error + .data +d119: .word 0x80000000, 134, 654 +c119: .asciiz "Array extends outside of memory." + .text + + + # Test #111 + # Array extends outside of memory, but wraps around to the beginning of memory again. + ####################################################################### + jal setSavedRegisters + la $a0, d121 # Array + jal Merge_Sort + + move $a0, $v0 # Result + li $a2, 111 # Test #111 + la $a3, c121 # Description of test + jal assertNull # Check for an error + .data +d121: .word 0xFFFFFFF8, 134, 654 +c121: .asciiz "Array wraps around to the beginning of memory." + .text + + + # Test #112 + # Array remains inside of memory but attempts to cross from the heap to the stack. + ####################################################################### + jal setSavedRegisters + la $a0, d123 # Array + sub $t0, $sp, $a0 + srl $t0, $t0, 2 + sw $t0, 0 ($a0) # Cracked length of the array. + jal Merge_Sort + + move $a0, $v0 # Result + li $a2, 112 # Test #112 + la $a3, c123 # Description of test + jal assertNull # Check for an error + .data +d123: .word 0, 134, 654 +c123: .asciiz "Array is inside of the memory range, but attempts to cross from the heap to the stack." + .text + + + + + + + +Skip_Parameter_Validation_Tests: + # All tests completed. + .data +t1: .asciiz "----------Starting functionality tests.----------\n" +t2: .asciiz "----------Starting parameter checking tests.----------\n" +f: .asciiz "----------Testing completed.----------\n" + .text + li $v0, 4 + la $a0, f + syscall + lw $ra, 0 ($sp) # Load return address + addi $sp, $sp, 4 # Pop the stack + jr $ra + + + + + + +############################################################################### +## Helper functions ## +############################################################################### + # Print List + # + # Displays the contents of a list. It does assume that you give it + # useful data to display. + # + # Parameters: + # $a0: A list + ####################################################################### +Print_List: + addi $sp, $sp, -20 + sw $t0, 0 ($sp) + sw $t1, 4 ($sp) + sw $t2, 8 ($sp) + sw $v0, 12 ($sp) + sw $s0, 16 ($sp) + + lw $t1, 0 ($a0) + li $t0, 0 + move $s0, $a0 + + .data +PL_S: .asciiz "List: " + .text + li $v0, 4 + la $a0, PL_S + syscall + +PL_Loop: + sll $t2, $t0, 2 + add $t2, $s0, $t2 + lw $a0, 4 ($t2) + li $v0, 1 + syscall + + addi $t0, $t0, 1 + bge $t0, $t1, PL_LoopEnd + + li $v0, 4 + la $a0, AEFPRA + syscall + j PL_Loop + +PL_LoopEnd: + li $v0, 4 + la $a0, nl + syscall + + lw $t0, 0 ($sp) + lw $t1, 4 ($sp) + lw $t2, 8 ($sp) + lw $v0, 12 ($sp) + lw $s0, 16 ($sp) + addi $sp, $sp, 20 + jr $ra + + + + + + + +############################################################################### +## Assertion functions ## +############################################################################### + # Assert Equality + # $a0: Observed + # $a1: Expected + # $a2: Test # + # $a3: Test description + # + # Data type options: + # Word // Works for any single 32-bit (or smaller) datum. + # List + # Linked List // Currently expects characters in the expected field. + ####################################################################### +assertEqual_Word: + bne $a0, $a1, AEFail_Word_NotEqual + + # Correct solution. + li $a0, 1 + j Results + +assertEqual_List: + # Check for obviously bad results first. + beqz $a0, AEFail_NullPointer # Check for a null pointer. + li $t0, -1 + beq $a0, $t0, AEFail_BadParameter # Check for the error condition. + blt $a0, 0x10008000, AEFail_NotAPointer # Check for addresses below the dynamic memory range. + bgeu $a0, $sp, AEFail_NotAPointer # Check for addresses above the dynamic memory range. + srl $t0, $a0, 2 + sll $t0, $t0, 2 + bne $a0, $t0, AEFail_NotAPointer # Check for a non-word aligned address. + beq $a0, $a1, AEFail_DuplicateDataStructure # Check for a copy of the expected solution as the observed data. + + # Comparing the results with the expected solution. + lw $t0, 0 ($a0) + lw $t1, 0 ($a1) + bne $t0, $t1, AEFail_List_LengthMismatch # Both lists should have the same length value. + + li $t0, 0 +List_Loop: + beq $t0, $t1, List_ObservedFinished + + sll $t2, $t0, 2 + add $t3, $a0, $t2 + add $t4, $a1, $t2 + + lw $t3, 4 ($t3) + lw $t4, 4 ($t4) + bne $t3, $t4, AEFail_List_Mismatch + + addi $t0, $t0, 1 + j List_Loop + +List_ObservedFinished: + # Correct Solution. + li $a0, 1 + j Results + + + +assertEqual_LinkedList: + # Check for obviously bad results first. + beqz $a0, AEFail_NullPointer # Check for a null pointer. + li $t0, -1 + beq $a0, $t0, AEFail_BadParameter # Check for the error condition. + blt $a0, 0x10008000, AEFail_NotAPointer # Check for addresses below the dynamic memory range. + bgeu $a0, $sp, AEFail_NotAPointer # Check for addresses above the dynamic memory range. + srl $t0, $a0, 2 + sll $t0, $t0, 2 + bne $a0, $t0, AEFail_NotAPointer # Check for a non-word aligned address. + beq $a0, $a1, AEFail_DuplicateDataStructure # Check for a copy of the expected solution as the observed data. + + # Comparing the results with the expected solution. + move $t0, $a0 + move $t1, $a1 +LinkedList_Loop: + lb $t2, 0 ($t1) + beqz $t0, LinkedList_ObservedFinished # A null pointer indicates the end of the observed result. + beqz $t2, AEFail_ObservedTooLong # The expected string is null terminated. + + lw $t3, 0 ($t0) + bne $t3, $t2, AEFail_LinkedList_Mismatch # Compare observed to expected. Yes, the word result really should equal the expected byte. + + lw $t0, 4 ($t0) # Get the next direction in the linked list. + addi $t1, $t1, 1 # Get the next character in the string. + + j LinkedList_Loop + +LinkedList_ObservedFinished: + bnez $t2, AEFail_ObservedTooShort # The expected string still has more instructions. + + # Correct solution. + li $a0, 1 + j Results + + + # Failed because a null pointer was observed. +AEFail_NullPointer: + li $a0, 0 + la $a1, AEFNP + j Results + .data +AEFNP: .asciiz "The function returned a null pointer.\nThis problem was solvable and should return a solution object.\n" + .text + + # Failed because an error was returned. +AEFail_BadParameter: + li $a0, 0 + la $a1, AEFBP + j Results + .data +AEFBP: .asciiz "The function returned an error.\nThis problem was solvable and should return a solution object.\n" + .text + + # Failed because some garbage was returned. +AEFail_NotAPointer: + li $a0, 0 + la $a1, AEFNAP + j Results + .data +AEFNAP: .asciiz "Your results could not be identified.\nThe function returned something other than a solution object.\n" + .text + + # Failed because both the expected data structure and the observed data structure occupy the same memory locations. +AEFail_DuplicateDataStructure: + li $a0, 0 + la $a1, AEFDDS + j Results + .data +AEFDDS: .asciiz "Cheating is bad, mmmkay?\nYes, we can detect when you pass the expected data structure as the result of your function.\n" + .text + + # Failed because the solution was longer than expected. +AEFail_ObservedTooLong: + li $a0, 0 + la $a1, AEFOTL + j Results + .data +AEFOTL: .asciiz "The function found the correct route, but included additional instructions after 'exit the maze.'\n" + .text + + # Failed because the solution was shorter than expected. + + # This method exploits the polymorphic detection available in the Results method. + # The address of some code to run is passed instead of the address of an error message. + # Once the Results method has completed the basic reporting, it will call the given + # function to complete printing a detailed error message and allow it to return to + # the original test code. +AEFail_ObservedTooShort: + addi $sp, $sp, -8 + sw $a0, 0 ($sp) + sw $a1, 4 ($sp) + li $a0, 0 + la $a1, AEFOTS + j Results +AEFOTS: li $v0, 4 + la $a0, AEFOTS1 + syscall + j AEF_Print_LinkedList_Results + .data +AEFOTS1: .asciiz "The function was on the correct path, but quit before the end.\n" + .text + + # Failed because the observed results did not match the expected results. +AEFail_LinkedList_Mismatch: + addi $sp, $sp, -8 + sw $a0, 0 ($sp) + sw $a1, 4 ($sp) + li $a0, 0 + la $a1, AEFM + j Results +AEFM: li $v0, 4 + la $a0, AEFM1 + syscall + j AEF_Print_LinkedList_Results + .data +AEFM1: .asciiz "The instructions returned are incorrect.\n" + .text + + # Displaying the observed and expected results. +AEF_Print_LinkedList_Results: + lw $t0, 0 ($sp) # Observed result + lw $t1, 4 ($sp) # Expected result + addi $sp, $sp, 8 + + li $v0, 4 + la $a0, AEFPRO + syscall + +AEFPRObservedLoop: + beqz $t0, AEFPRObservedLoopEnd + + li $v0, 4 + la $a0, AEFPRA + syscall + + li $v0, 11 + lw $a0, 0 ($t0) + syscall + + lw $t0, 4 ($t0) + j AEFPRObservedLoop + +AEFPRObservedLoopEnd: + + li $v0, 4 + la $a0, nl + syscall + la $a0, AEFPRE + syscall + +AEFPRExpectedLoop: + lb $t2, 0 ($t1) + beqz $t2, AEFPRExpectedLoopEnd + + li $v0, 4 + la $a0, AEFPRA + syscall + + li $v0, 11 + move $a0, $t2 + syscall + + addi $t1, $t1, 1 + j AEFPRExpectedLoop + +AEFPRExpectedLoopEnd: + li $v0, 4 + la $a0, nl + syscall + syscall + + jr $ra + + + .data +AEFPRO: .asciiz "Observed: " +AEFPRE: .asciiz "Expected: " +AEFPRA: .asciiz ", " + .text + + # Failed because the length of the observed list did not match the expected length. +AEFail_List_LengthMismatch: + addi $sp, $sp, -8 + sw $a0, 0 ($sp) + sw $a1, 4 ($sp) + li $a0, 0 + la $a1, AEFLLM + j Results +AEFLLM: li $v0, 4 + la $a0, AEFLLM1 + syscall + la $a0, AEFPRO + syscall + li $v0, 1 + lw $a0, 0 ($sp) + lw $a0, 0 ($a0) + syscall + li $v0, 4 + la $a0, AEFPRE + syscall + li $v0, 1 + lw $a0, 4 ($sp) + lw $a0, 0 ($a0) + syscall + addi $sp, $sp, 8 + jr $ra + .data +AEFLLM1:.asciiz "The length of the given list does not match the length of the expected result.\n" + .text + + # Failed because the data in the list did not match the expected data. +AEFail_List_Mismatch: + addi $sp, $sp, -8 + sw $a0, 0 ($sp) + sw $a1, 4 ($sp) + li $a0, 0 + la $a1, AEFLM + j Results +AEFLM: lw $t8, 0 ($sp) + lw $t9, 4 ($sp) + addi $sp, $sp, 8 + + li $v0, 4 + la $a0, AEFLM1 + syscall + li $v0, 4 + la $a0, AEFPRO + syscall + + li $t0, 0 + lw $t1, 0 ($t8) +List_Mismatch_ObservedLoop: + li $v0, 1 + sll $t2, $t0, 2 + add $t2, $t8, $t2 + lw $a0, 4 ($t2) + syscall + + addi $t0, $t0, 1 + beq $t0, $t1, List_Mismatch_ObservedLoopEnd + + li $v0, 4 + la $a0, AEFPRA + syscall + j List_Mismatch_ObservedLoop + +List_Mismatch_ObservedLoopEnd: + li $v0, 4 + la $a0, nl + syscall + + li $v0, 4 + la $a0, AEFPRE + syscall + li $t0, 0 +List_Mismatch_ExpectedLoop: + li $v0, 1 + sll $t2, $t0, 2 + add $t2, $t9, $t2 + lw $a0, 4 ($t2) + syscall + + addi $t0, $t0, 1 + beq $t0, $t1, List_Mismatch_ExpectedLoopEnd + + li $v0, 4 + la $a0, AEFPRA + syscall + j List_Mismatch_ExpectedLoop + +List_Mismatch_ExpectedLoopEnd: + li $v0, 4 + la $a0, nl + syscall + syscall + + jr $ra + + + .data +AEFLM1: .asciiz "The data in the observed list does not match the expected data.\n" + .text + + # Failed because the observed data did not match the expected data. +AEFail_Word_NotEqual: + addi $sp, $sp, -8 + sw $a0, 0 ($sp) + sw $a1, 4 ($sp) + li $a0, 0 + la $a1, AEFWNE + j Results +AEFWNE: li $v0, 4 + la $a0, AEFWNE1 + syscall + la $a0, AEFPRO + syscall + li $v0, 1 + lw $a0, 0 ($sp) + syscall + li $v0, 4 + la $a0, AEFPRE + syscall + li $v0, 1 + lw $a0, 4 ($sp) + addi $sp, $sp, 8 + jr $ra + .data +AEFWNE1:.asciiz "The observed data does not match the expected data.\n" + .text + + + + + ####################################################################### + # Assert Null Pointer + # $a0: Observed + # : Expect a null pointer (0). + # $a2: Test # + # $a3: Test description + ####################################################################### +assertNull: + bnez $a0, AN_Failed + + li $a0, 1 # Correct result. + j Results + +AN_Failed: + li $a0, 0 # Incorrect result. + la $a1, ANF # Description of failure. + j Results + .data +ANF: .asciiz "Null pointer expected. This problem was not solvable.\n" + .text + + + + + + ####################################################################### + # Assert Error + # $a0: Observed + # : Expect an error signal (-1). + # $a2: Test # + # $a3: Test description + ####################################################################### +assertError: + li $t0, -1 + bne $a0, $t0, AE_Failed + + li $a0, 1 # Correct result. + j Results + +AE_Failed: + li $a0, 0 # Incorrect result. + la $a1, AEF # Description of failure. + j Results + .data +AEF: .asciiz "The parameters were not parsable, the function should have returned an error (-1).\n" + .text + + + + + + # Results + # + # Display the results of the test. + # $a0: Pass (1) or fail (0). + # $a1: Description of failure if needed. + # $a2: Test # + # $a3: Test description + ####################################################################### +Results: + bnez $a0, checkSavedRegisters +Res1: move $t0, $a0 + move $t1, $a1 + move $t2, $a2 + move $t3, $a3 + # Print the header. + li $v0, 4 + la $a0, R1 + syscall + li $v0, 1 + move $a0, $t2 + syscall + + bnez $t0, RPass + + # Failed the test. + li $v0, 4 + la $a0, RF + syscall + move $a0, $t3 + syscall + la $a0, nl + syscall + blt $t1, 0x10000000, RPrintFunction + move $a0, $t1 # Displaying a simple error message. + syscall + la $a0, nl + syscall + jr $ra +RPrintFunction: # Calling a print function for extra detail. + jr $t1 + + # Passed the test. +RPass: li $v0, 4 + la $a0, RP + syscall + move $a0, $t3 + syscall + la $a0, nl + syscall + jr $ra + + .data +R1: .asciiz "Test #" +nl: .asciiz "\n" +RP: .asciiz " passed: " +RF: .asciiz " failed: " + .text + + + + + # Set Saved Registers + ####################################################################### +setSavedRegisters: + li $s0, 14 + li $s1, 73 + li $s2, 69 + li $s3, 46 + li $s4, 79 + li $s5, 92 + li $s6, 37 + li $s7, 96 + li $t0, 14 + li $t1, -72 + li $t2, 12331 + li $t3, 18 + li $t4, 456 + li $t5, 09876 + li $t6, 6789 + li $t7, 3443 + li $t8, 2343 + li $t9, 98 + li $v0, 3876 + li $v1, 3443 + li $a0, 23453 + li $a1, 34432 + li $a2, 543 + li $a3, -234543 + jr $ra + + # Check Saved Registers + ####################################################################### +checkSavedRegisters: + bne $s0, 14, regFail + bne $s1, 73, regFail + bne $s2, 69, regFail + bne $s3, 46, regFail + bne $s4, 79, regFail + bne $s5, 92, regFail + bne $s6, 37, regFail + bne $s7, 96, regFail + j Res1 + +regFail: + .data +rf: .asciiz "Your function returned the correct value, but has changed the saved registers.\nYou must follow the conventions and restore the state of any saved register ($s0-$s7) when you're finished with it.\n" + .text + li $a0, 0 + la $a1, rf + j Res1 +