From 2bf5effe95641667a1ed51c04eff7760f6a42ef4 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Mon, 3 Oct 2016 13:00:14 +0200 Subject: Initial --- biginttest.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100755 biginttest.py (limited to 'biginttest.py') diff --git a/biginttest.py b/biginttest.py new file mode 100755 index 0000000..f125953 --- /dev/null +++ b/biginttest.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python3 +import sys, random, subprocess + +ntimes=10000 +maxn=1e100 + +def check(desc,x,y): + if x==y: return + print("{}: {} != {}".format(desc,x,y)) + assert False + +def gendata(): + for _ in range(ntimes): + yield random.randint(0,maxn), random.randint(1,maxn) + +def proctest(): + proc=subprocess.Popen(["./main"],stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=sys.stderr) + + for (a,b) in gendata(): + proc.stdin.write("div {} {}\n".format(a,b).encode("ascii")) + proc.stdin.write("mod {} {}\n".format(a,b).encode("ascii")) + proc.stdin.flush() + + ans=int(proc.stdout.readline()) + check("{}/{}".format(a,b),ans,a//b) + + ans=int(proc.stdout.readline()) + check("{}%{}".format(a,b),ans,a%b) + + proc.kill() + +def justprint(): + for (a,b) in gendata(): + print("div {} {}".format(a,b)) + print("mod {} {}".format(a,b)) + +#justprint() +proctest() -- cgit v1.2.3-54-g00ecf