Add Python script to test the challenges directly
This commit is contained in:
parent
c565413152
commit
d93cb45a1f
3 changed files with 159 additions and 0 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -2,3 +2,4 @@
|
|||
build/
|
||||
compile_commands.json
|
||||
.clangd/
|
||||
tests/.mypy_cache/
|
||||
|
|
79
tests/challenges.py
Executable file
79
tests/challenges.py
Executable file
|
@ -0,0 +1,79 @@
|
|||
#!/usr/bin/env python3
|
||||
from typing import List
|
||||
import subprocess
|
||||
|
||||
|
||||
def run_challenge(challenge: int, inputs: List[str], expected: List[str]) -> None:
|
||||
print(f"[challenge {challenge:02}]", end=" ")
|
||||
res = subprocess.run(
|
||||
[f"../build/ex{challenge:02}", *inputs],
|
||||
capture_output=True,
|
||||
check=True,
|
||||
text=True,
|
||||
)
|
||||
|
||||
if not expected:
|
||||
print(res.stdout)
|
||||
return
|
||||
|
||||
assert all(
|
||||
out in res.stdout for out in expected
|
||||
), f"Expected output:\n{expected}\nActual output:\n{res.stdout}"
|
||||
|
||||
print("OK")
|
||||
|
||||
|
||||
def main():
|
||||
run_challenge(
|
||||
challenge=1,
|
||||
inputs=[
|
||||
"49276d206b696c6c696e6720796f757220627261696e206c69"
|
||||
"6b65206120706f69736f6e6f7573206d757368726f6f6d"
|
||||
],
|
||||
expected=["SSdtIGtpbGxpbmcgeW91ciBicmFpbiBsaWtlIGEgcG9pc29ub3VzIG11c2hyb29t"],
|
||||
)
|
||||
|
||||
run_challenge(
|
||||
challenge=2,
|
||||
inputs=[
|
||||
"1c0111001f010100061a024b53535009181c",
|
||||
"686974207468652062756c6c277320657965",
|
||||
],
|
||||
expected=["746865206b696420646f6e277420706c6179"],
|
||||
)
|
||||
|
||||
run_challenge(
|
||||
challenge=3,
|
||||
inputs=["1b37373331363f78151b7f2b783431333d78397828372d363c78373e783a393b3736"],
|
||||
expected=["Cooking MC's like a pound of bacon"],
|
||||
)
|
||||
|
||||
run_challenge(
|
||||
challenge=4, inputs=["../data/4.txt"], expected=["Now that the party is jumping\\n"],
|
||||
)
|
||||
|
||||
run_challenge(
|
||||
challenge=5,
|
||||
inputs=["ICE", "../data/5.txt"],
|
||||
expected=[
|
||||
"0b3637272a2b2e63622c2e69692a23693a2a3c6324202d623d"
|
||||
"63343c2a26226324272765272a282b2f20430a652e2c652a31"
|
||||
"24333a653e2b2027630c692b20283165286326302e27282f"
|
||||
],
|
||||
)
|
||||
|
||||
with open("output6.txt", "r") as f:
|
||||
output6 = f.read()
|
||||
run_challenge(
|
||||
challenge=6,
|
||||
inputs=["../data/6.txt"],
|
||||
expected=["Terminator X: Bring the noise", output6],
|
||||
)
|
||||
|
||||
run_challenge(
|
||||
challenge=7, inputs=["YELLOW SUBMARINE", "../data/7.txt"], expected=[output6],
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
79
tests/output6.txt
Normal file
79
tests/output6.txt
Normal file
|
@ -0,0 +1,79 @@
|
|||
I'm back and I'm ringin' the bell
|
||||
A rockin' on the mike while the fly girls yell
|
||||
In ecstasy in the back of me
|
||||
Well that's my DJ Deshay cuttin' all them Z's
|
||||
Hittin' hard and the girlies goin' crazy
|
||||
Vanilla's on the mike, man I'm not lazy.
|
||||
|
||||
I'm lettin' my drug kick in
|
||||
It controls my mouth and I begin
|
||||
To just let it flow, let my concepts go
|
||||
My posse's to the side yellin', Go Vanilla Go!
|
||||
|
||||
Smooth 'cause that's the way I will be
|
||||
And if you don't give a damn, then
|
||||
Why you starin' at me
|
||||
So get off 'cause I control the stage
|
||||
There's no dissin' allowed
|
||||
I'm in my own phase
|
||||
The girlies sa y they love me and that is ok
|
||||
And I can dance better than any kid n' play
|
||||
|
||||
Stage 2 -- Yea the one ya' wanna listen to
|
||||
It's off my head so let the beat play through
|
||||
So I can funk it up and make it sound good
|
||||
1-2-3 Yo -- Knock on some wood
|
||||
For good luck, I like my rhymes atrocious
|
||||
Supercalafragilisticexpialidocious
|
||||
I'm an effect and that you can bet
|
||||
I can take a fly girl and make her wet.
|
||||
|
||||
I'm like Samson -- Samson to Delilah
|
||||
There's no denyin', You can try to hang
|
||||
But you'll keep tryin' to get my style
|
||||
Over and over, practice makes perfect
|
||||
But not if you're a loafer.
|
||||
|
||||
You'll get nowhere, no place, no time, no girls
|
||||
Soon -- Oh my God, homebody, you probably eat
|
||||
Spaghetti with a spoon! Come on and say it!
|
||||
|
||||
VIP. Vanilla Ice yep, yep, I'm comin' hard like a rhino
|
||||
Intoxicating so you stagger like a wino
|
||||
So punks stop trying and girl stop cryin'
|
||||
Vanilla Ice is sellin' and you people are buyin'
|
||||
'Cause why the freaks are jockin' like Crazy Glue
|
||||
Movin' and groovin' trying to sing along
|
||||
All through the ghetto groovin' this here song
|
||||
Now you're amazed by the VIP posse.
|
||||
|
||||
Steppin' so hard like a German Nazi
|
||||
Startled by the bases hittin' ground
|
||||
There's no trippin' on mine, I'm just gettin' down
|
||||
Sparkamatic, I'm hangin' tight like a fanatic
|
||||
You trapped me once and I thought that
|
||||
You might have it
|
||||
So step down and lend me your ear
|
||||
'89 in my time! You, '90 is my year.
|
||||
|
||||
You're weakenin' fast, YO! and I can tell it
|
||||
Your body's gettin' hot, so, so I can smell it
|
||||
So don't be mad and don't be sad
|
||||
'Cause the lyrics belong to ICE, You can call me Dad
|
||||
You're pitchin' a fit, so step back and endure
|
||||
Let the witch doctor, Ice, do the dance to cure
|
||||
So come up close and don't be square
|
||||
You wanna battle me -- Anytime, anywhere
|
||||
|
||||
You thought that I was weak, Boy, you're dead wrong
|
||||
So come on, everybody and sing this song
|
||||
|
||||
Say -- Play that funky music Say, go white boy, go white boy go
|
||||
play that funky music Go white boy, go white boy, go
|
||||
Lay down and boogie and play that funky music till you die.
|
||||
|
||||
Play that funky music Come on, Come on, let me hear
|
||||
Play that funky music white boy you say it, say it
|
||||
Play that funky music A little louder now
|
||||
Play that funky music, white boy Come on, Come on, Come on
|
||||
Play that funky music
|
Loading…
Add table
Add a link
Reference in a new issue