aboutsummaryrefslogtreecommitdiff
path: root/biginttest.py
blob: f125953d79f7677812ed4011e392be5a3ced60ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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()