def assert2ring(self, seed, tape, reps, pats, out): result = deco.run([str(seed), tape, str(reps), *pats]) output = '\n'.join(out) + '\n' self.assertEqual(result.returncode, 0) self.assertEqual(result.stderr, '') self.assertEqual(result.stdout, output)
def assertswitcher(self, a, output): result = deco.run([str(a)]) # run the test self.assertEqual(result.returncode, 0) # passing return code of 1 self.assertEqual(result.stderr, "") # no error on exit self.assertEqual( result.stdout, output # output matches expected )
def test_usage(self): result = deco.run([]) self.assertEqual(result.returncode, 1) self.assertEqual( result.stdout, 'USAGE: ' + deco.PATH + ' [seed] [tape] [iters] [src:dst ...]\n') self.assertEqual(result.stderr, '')
def test_usage(self): result = deco.run([]) self.assertEqual(result.returncode, 0) self.assertEqual(result.stderr, '') self.assertEqual(result.stdout, ( 'USAGE: ./habidasher [input]\n' ))
def test_usage(self): result = deco.run([]) self.assertEqual(result.returncode, 2) self.assertEqual(result.stdout, '') self.assertIn( "panic: runtime error: index out of range [1] with length 1", result.stderr)
def assertGCD(self, a, b, c): result = deco.run([str(a), str(b)], timeout=0.1) self.assertEqual(result.returncode, 0) self.assertEqual(result.stderr, '') expected = "foo(%d, %d) = %d\n" % (a, b, c) self.assertEqual(result.stdout, expected)
def test_invalid_arguments(self): result = deco.run(['hi there'], timeout=0.1) self.assertEqual(result.returncode, 0) self.assertEqual(result.stderr, '') expected = "is_prime(%d) = %d\n" % (0, 0) self.assertEqual(result.stdout, expected)
def assertPRIME(self, a, b): result = deco.run([str(a)]) print(result) self.assertEqual(result.returncode, 0) self.assertEqual(result.stderr, '') expected = "is_prime(%d) = %d\n" % (a, b) self.assertEqual(result.stdout, expected)
def test_sdbm(self): result = deco.run(['jdfgsdhfsdfsd 6445dsfsd7fg/*/+bfjsdgf%$^']) self.assertEqual(result.returncode, 0) self.assertEqual(result.stderr, '') self.assertIn( 'sdbm: 1942d093', result.stdout )
def test_djb2(self): result = deco.run(['jdfgsdhfsdfsd 6445dsfsd7fg/*/+bfjsdgf%$^']) self.assertEqual(result.returncode, 0) self.assertEqual(result.stderr, '') self.assertIn( 'djb2: 98c22a14', result.stdout )
def assert_rootkit(self, expected, items): stdin = '\n'.join("%s %d" % (a, b) for a, b in items) result = deco.run([], input=stdin) expect = 'find_rootkit() = %d\n' % expected self.assertEqual(result.returncode, 0) self.assertEqual(result.stdout, expect) self.assertEqual(result.stderr, '')
def test_go_home(self): result = deco.run([], input='77\n') self.assertEqual(result.returncode, 1) self.assertEqual(result.stderr, '') self.assertIn( 'Go home. You\'re drunk.', result.stdout )
def test_create_beer(self): result = deco.run([], input=CREATE_X_PORTER + '5\n') self.assertEqual(result.returncode, 0) self.assertEqual(result.stderr, '') self.assertIn( 'You brew up a Porter called X.\n', result.stdout )
def test_no_beer_here(self): result = deco.run([], input='4\n5\n') self.assertEqual(result.returncode, 0) self.assertEqual(result.stderr, '') self.assertIn( 'There\'s no beer here :(', result.stdout )
def test_exit(self): result = deco.run([], input='5\n') self.assertEqual(result.returncode, 0) self.assertEqual(result.stderr, '') self.assertIn( 'And one for the road!', result.stdout )
def test_bad_date(self): result = deco.run(['1942-19-42']) self.assertEqual(result.returncode, -4) self.assertEqual(result.stdout, '') self.assertIn( 'Unexpectedly found nil while unwrapping an Optional value', result.stderr )
def test_too_long(self): result = deco.run(['255', 'Actually I lied...']) self.assertEqual(result.returncode, 0) self.assertEqual(result.stderr, '') self.assertEqual(result.stdout, 'SIZE: 255\n' 'Too long!\n' )
def test_regular(self): result = deco.run(['14', 'seven chickens']) self.assertEqual(result.returncode, 0) self.assertEqual(result.stderr, '') self.assertEqual(result.stdout, 'SIZE: 14\n' 'Got: seven chickens\n' )
def test_not_an_option(self): result = deco.run([], input='1\n88\n') self.assertEqual(result.returncode, 2) self.assertEqual(result.stderr, '') self.assertIn( 'That\'s not an option.\n', result.stdout )
def test_both(self): result = deco.run(['The quick brown fox jumps over the lazy dog.']) self.assertEqual(result.returncode, 0) self.assertEqual(result.stderr, '') self.assertEqual(result.stdout, ( 'djb2: ce5354cc\n' 'sdbm: 0ea7eb7b\n' ))
def assertBirthday(self, date, name): result = deco.run([date]) self.assertEqual(result.returncode, 0) self.assertEqual(result.stderr, '') self.assertIn( 'It\'s ' + name + '\'s birthday!', result.stdout )
def test_list_beers(self): cmd = CREATE_X_PORTER + CREATE_SPROUTS + '2\n5\n' result = deco.run([], input=cmd) self.assertEqual(result.returncode, 0) self.assertEqual(result.stderr, '') self.assertIn( ' 1) A 2-week-old Porter called X.\n' ' 2) A 1-week-old Belgian called Sprouts.\n', result.stdout )
def test_drink_beer(self): cmd = CREATE_X_PORTER cmd += '4\n4\n4\n' + '2\n5\n' result = deco.run([], input=cmd) self.assertEqual(result.returncode, 0) self.assertEqual(result.stderr, '') self.assertIn( ' 1) A 4-week-old Porter called X.\n', result.stdout )
def test_boring_date(self): # Bastille Day result = deco.run(['1789-07-14']) self.assertEqual(result.returncode, 0) self.assertEqual(result.stderr, '') self.assertEqual( 'That\'s a Tuesday in July.\n' 'What a boring day.\n', result.stdout )
def test_june(self): # World Refrigeration Day result = deco.run(['1824-06-26']) self.assertEqual(result.returncode, 0) self.assertEqual(result.stderr, '') self.assertEqual( 'That\'s a Saturday in June.\n' 'June is a good month.\n', result.stdout )
def test_ringo(self): # Ringo's Birthday result = deco.run(['1940-07-07']) self.assertEqual(result.returncode, 0) self.assertEqual(result.stderr, '') self.assertEqual( 'That\'s a Sunday in July.\n' 'It\'s Ringo\'s birthday!\n', result.stdout )
def test_unknown_person(self): result = deco.run(['Alice'], input=('Grandma ??? ???\n' 'Grandpa ??? ???\n' 'Dad Grandma Grandpa\n' 'Mom Carlita Javier\n' 'Alice Mom Dad\n')) self.assertEqual(result.returncode, 2) self.assertEqual(result.stdout, '') self.assertEqual('Unknown person: Carlita\n', result.stderr)
def test_ancestors(self): result = deco.run(['Eve'], input=PEDIGREE) self.assertEqual(result.returncode, 0) self.assertEqual(result.stderr, '') self.assertTrue(result.stdout.endswith('Eve\'s Descendants:\n')) people = self.collect(result.stdout) self.assertEqual( people, set([ 'Adam', 'Alice', 'Amy', 'Bart', 'Beth', 'Bob', 'Carol', 'Dave' ]))
def _assertCarshop(self, params, available, scenario=0, expected_stderr=''): warehouse_input = [ 'BMW M3 2019 5432 Jade\n' \ 'Mercedes-Benz CLS-Class 2015 15473 Charcoal\n' \ 'Porsche Cayenne 2018 10349 Platinum\n', 'Volkswagen Atlas 2019 19034 Aurora\n' \ 'Porsche Panamera 2016 65198 Charcoal\n' \ 'Audi A7 2020 30595 Jade\n', 'BMW M5 2014 80945 Indigo\n' \ 'Mercedes-Benz AMG-GT 2016 34095 Charcoal\n' \ 'Porsche Cayenne 2020 30253 Jade\n', 'These are not decimal values\n' \ 'Are you capable of strings?\n' \ 'We will find it out', ] warehouse_output = [ '[{2019 BMW M3 (Jade, 5432 miles)} ' \ '{2015 Mercedes-Benz CLS-Class (Charcoal, 15473 miles)} ' \ '{2018 Porsche Cayenne (Platinum, 10349 miles)}]', '[{2019 Volkswagen Atlas (Aurora, 19034 miles)} ' \ '{2016 Porsche Panamera (Charcoal, 65198 miles)} ' \ '{2020 Audi A7 (Jade, 30595 miles)}]', '[{2014 BMW M5 (Indigo, 80945 miles)} ' \ '{2016 Mercedes-Benz AMG-GT (Charcoal, 34095 miles)} ' \ '{2020 Porsche Cayenne (Jade, 30253 miles)}]', '[{0 These are (Aurora, 0 miles)} ' \ '{0 Are you (Aurora, 0 miles)} ' \ '{0 We will (Aurora, 0 miles)}]', ] result = deco.run(params, input=warehouse_input[scenario]) expected_stdout = f"Welcome to {params[0]}'s Car Shop!\n" expected_stdout += 'Available Cars:\n' expected_stdout += warehouse_output[scenario] + '\n' if available: expected_stdout += 'This car is available!\n' else: expected_stdout += 'This car is not available. :-(\n' self.assertEqual(result.returncode, 0) self.assertEqual(result.stderr, expected_stderr) self.assertEqual(result.stdout, expected_stdout)
def test_sell_beer(self): cmd = CREATE_X_PORTER + CREATE_SPROUTS cmd += '3\n1\n' + '2\n5\n' result = deco.run([], input=cmd) self.assertEqual(result.returncode, 0) self.assertEqual(result.stderr, '') self.assertIn( 'You sell your X Porter for $1100.\n', result.stdout ) self.assertIn( ' 1) A 2-week-old Belgian called Sprouts.\n', result.stdout )