summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rwxr-xr-xtests/basics/run-tests43
-rw-r--r--tests/basics/tests/0prelim.py4
-rw-r--r--tests/basics/tests/builtin-len1.py13
-rw-r--r--tests/basics/tests/class1.py28
-rw-r--r--tests/basics/tests/class2.py15
-rw-r--r--tests/basics/tests/comprehension1.py20
-rw-r--r--tests/basics/tests/dict1.py18
-rw-r--r--tests/basics/tests/dict2.py10
-rw-r--r--tests/basics/tests/float1.py3
-rw-r--r--tests/basics/tests/for1.py9
-rw-r--r--tests/basics/tests/fun1.py5
-rw-r--r--tests/basics/tests/fun2.py10
-rw-r--r--tests/basics/tests/fun3.py6
-rw-r--r--tests/basics/tests/generator1.py22
-rw-r--r--tests/basics/tests/lambda1.py4
-rw-r--r--tests/basics/tests/list1.py12
-rw-r--r--tests/basics/tests/set1.py7
-rw-r--r--tests/basics/tests/string1.py9
-rw-r--r--tests/basics/tests/try1.py6
-rw-r--r--tests/basics/tests/try2.py12
-rw-r--r--tests/basics/tests/try3.py17
-rw-r--r--tests/basics/tests/try4.py21
-rw-r--r--tests/basics/tests/while1.py12
23 files changed, 306 insertions, 0 deletions
diff --git a/tests/basics/run-tests b/tests/basics/run-tests
new file mode 100755
index 0000000000..6315b67509
--- /dev/null
+++ b/tests/basics/run-tests
@@ -0,0 +1,43 @@
+#!/bin/bash
+
+RM="/bin/rm -f"
+CPYTHON3=python3
+MP_PY=../../unix/py
+
+numtests=0
+numpassed=0
+numfailed=0
+namefailed=
+
+for infile in tests/*.py
+do
+ basename=`basename $infile .c`
+ outfile=${basename}.out
+ expfile=${basename}.exp
+
+ $CPYTHON3 -B $infile > $expfile
+ $MP_PY $infile > $outfile
+
+ diff --brief $expfile $outfile > /dev/null
+
+ if [ $? -eq 0 ]
+ then
+ echo "pass $infile"
+ $RM $outfile
+ $RM $expfile
+ numpassed=`expr $numpassed + 1`
+ else
+ echo "FAIL $infile"
+ numfailed=`expr $numfailed + 1`
+ namefailed="$namefailed $basename"
+ fi
+
+ numtests=`expr $numtests + 1`
+done
+
+echo "$numtests tests performed"
+echo "$numpassed tests passed"
+if [ $numfailed -ne 0 ]
+then
+ echo "$numfailed tests failed -$namefailed"
+fi
diff --git a/tests/basics/tests/0prelim.py b/tests/basics/tests/0prelim.py
new file mode 100644
index 0000000000..2da65dc279
--- /dev/null
+++ b/tests/basics/tests/0prelim.py
@@ -0,0 +1,4 @@
+# all tests need print to work! make sure it does work
+
+print(1)
+print('abc')
diff --git a/tests/basics/tests/builtin-len1.py b/tests/basics/tests/builtin-len1.py
new file mode 100644
index 0000000000..6a082394c2
--- /dev/null
+++ b/tests/basics/tests/builtin-len1.py
@@ -0,0 +1,13 @@
+# builtin len
+
+print(len(()))
+print(len((1,)))
+print(len((1, 2)))
+
+print(len([]))
+x = [1, 2, 3]
+print(len(x))
+
+f = len
+print(f({}))
+print(f({1:2, 3:4}))
diff --git a/tests/basics/tests/class1.py b/tests/basics/tests/class1.py
new file mode 100644
index 0000000000..bf5f08e64e
--- /dev/null
+++ b/tests/basics/tests/class1.py
@@ -0,0 +1,28 @@
+# basic class
+
+def go():
+ class C:
+ def f():
+ print(1)
+
+ def g(self):
+ print(2)
+
+ def set(self, value):
+ self.value = value
+
+ def print(self):
+ print(self.value)
+
+ C.f()
+ C()
+ C().g()
+
+ o = C()
+ o.set(3)
+ o.print()
+
+ C.set(o, 4)
+ C.print(o)
+
+go()
diff --git a/tests/basics/tests/class2.py b/tests/basics/tests/class2.py
new file mode 100644
index 0000000000..0b3b218672
--- /dev/null
+++ b/tests/basics/tests/class2.py
@@ -0,0 +1,15 @@
+# class with __init__
+
+class C1:
+ def __init__(self):
+ self.x = 1
+
+c1 = C1()
+print(c1.x)
+
+class C2:
+ def __init__(self, x):
+ self.x = x
+
+c2 = C2(4)
+print(c2.x)
diff --git a/tests/basics/tests/comprehension1.py b/tests/basics/tests/comprehension1.py
new file mode 100644
index 0000000000..7f541ee53f
--- /dev/null
+++ b/tests/basics/tests/comprehension1.py
@@ -0,0 +1,20 @@
+def f():
+ # list comprehension
+
+ print([a + 1 for a in range(5)])
+ print([(a, b) for a in range(3) for b in range(2)])
+ print([a * 2 for a in range(7) if a > 3])
+
+ print([a for a in [1, 3, 5]])
+ print([a for a in [a for a in range(4)]])
+
+ # dict comprehension
+
+ d = {a : 2 * a for a in range(5)}
+ print(d[0], d[1], d[2], d[3], d[4])
+
+ # set comprehension
+
+ print({a for a in range(5)})
+
+f()
diff --git a/tests/basics/tests/dict1.py b/tests/basics/tests/dict1.py
new file mode 100644
index 0000000000..1356cd4280
--- /dev/null
+++ b/tests/basics/tests/dict1.py
@@ -0,0 +1,18 @@
+# basic dictionary
+
+d = {}
+print(d)
+d[2] = 123
+print(d)
+d = {1:2}
+d[3] = 3
+print(d)
+d[1] = 0
+print(d)
+print(d[1])
+
+x = 1
+while x < 1000:
+ d[x] = x
+ x += 1
+print(d[500])
diff --git a/tests/basics/tests/dict2.py b/tests/basics/tests/dict2.py
new file mode 100644
index 0000000000..1d5aae576b
--- /dev/null
+++ b/tests/basics/tests/dict2.py
@@ -0,0 +1,10 @@
+# using strings as keys in dict
+
+d = {'1': 1, '2': 2}
+print(d['1'], d['2'])
+
+d['3'] = 3
+print(d['1'], d['2'], d['3'])
+
+d['2'] = 222
+print(d['1'], d['2'], d['3'])
diff --git a/tests/basics/tests/float1.py b/tests/basics/tests/float1.py
new file mode 100644
index 0000000000..200d955856
--- /dev/null
+++ b/tests/basics/tests/float1.py
@@ -0,0 +1,3 @@
+# basic float
+x = 1 / 2
+print(x)
diff --git a/tests/basics/tests/for1.py b/tests/basics/tests/for1.py
new file mode 100644
index 0000000000..5a2635638d
--- /dev/null
+++ b/tests/basics/tests/for1.py
@@ -0,0 +1,9 @@
+# basic for loop
+
+def f():
+ for x in range(2):
+ for y in range(2):
+ for z in range(2):
+ print(x, y, z)
+
+f()
diff --git a/tests/basics/tests/fun1.py b/tests/basics/tests/fun1.py
new file mode 100644
index 0000000000..e12bdbe03e
--- /dev/null
+++ b/tests/basics/tests/fun1.py
@@ -0,0 +1,5 @@
+# calling a function
+
+def f():
+ print(1)
+f()
diff --git a/tests/basics/tests/fun2.py b/tests/basics/tests/fun2.py
new file mode 100644
index 0000000000..a3c3e7babf
--- /dev/null
+++ b/tests/basics/tests/fun2.py
@@ -0,0 +1,10 @@
+# calling a function from a function
+
+def f(x):
+ print(x + 1)
+
+def g(x):
+ f(2 * x)
+ f(4 * x)
+
+g(3)
diff --git a/tests/basics/tests/fun3.py b/tests/basics/tests/fun3.py
new file mode 100644
index 0000000000..f1458df823
--- /dev/null
+++ b/tests/basics/tests/fun3.py
@@ -0,0 +1,6 @@
+# function with large number of arguments
+
+def fun(a, b, c, d, e, f, g):
+ return a + b + c * d + e * f * g
+
+print(fun(1, 2, 3, 4, 5, 6, 7))
diff --git a/tests/basics/tests/generator1.py b/tests/basics/tests/generator1.py
new file mode 100644
index 0000000000..d4028b0ce3
--- /dev/null
+++ b/tests/basics/tests/generator1.py
@@ -0,0 +1,22 @@
+def f(x):
+ print('a')
+ y = x
+ print('b')
+ while y > 0:
+ print('c')
+ y -= 1
+ print('d')
+ yield y
+ print('e')
+ print('f')
+ return None
+
+for val in f(3):
+ print(val)
+
+#gen = f(3)
+#print(gen)
+#print(gen.__next__())
+#print(gen.__next__())
+#print(gen.__next__())
+#print(gen.__next__())
diff --git a/tests/basics/tests/lambda1.py b/tests/basics/tests/lambda1.py
new file mode 100644
index 0000000000..06111d6a93
--- /dev/null
+++ b/tests/basics/tests/lambda1.py
@@ -0,0 +1,4 @@
+# lambda
+
+f = lambda x, y: x + 3 * y
+print(f(3, 5))
diff --git a/tests/basics/tests/list1.py b/tests/basics/tests/list1.py
new file mode 100644
index 0000000000..8caa9e17c6
--- /dev/null
+++ b/tests/basics/tests/list1.py
@@ -0,0 +1,12 @@
+# basic list functionality
+x = [1, 2, 3 * 4]
+print(x)
+x[0] = 4
+print(x)
+x[1] += -4
+print(x)
+x.append(5)
+print(x)
+f = x.append
+f(4)
+print(x)
diff --git a/tests/basics/tests/set1.py b/tests/basics/tests/set1.py
new file mode 100644
index 0000000000..c54fbd8379
--- /dev/null
+++ b/tests/basics/tests/set1.py
@@ -0,0 +1,7 @@
+# basic sets
+
+s = {1}
+print(s)
+
+s = {3, 4, 3, 1}
+print(s)
diff --git a/tests/basics/tests/string1.py b/tests/basics/tests/string1.py
new file mode 100644
index 0000000000..28aeaddbc4
--- /dev/null
+++ b/tests/basics/tests/string1.py
@@ -0,0 +1,9 @@
+# basic strings
+
+x = 'abc'
+print(x)
+
+x += 'def'
+print(x)
+
+print('123' + "456")
diff --git a/tests/basics/tests/try1.py b/tests/basics/tests/try1.py
new file mode 100644
index 0000000000..b3b85372d7
--- /dev/null
+++ b/tests/basics/tests/try1.py
@@ -0,0 +1,6 @@
+# basic exceptions
+x = 1
+try:
+ x.a()
+except:
+ print(x)
diff --git a/tests/basics/tests/try2.py b/tests/basics/tests/try2.py
new file mode 100644
index 0000000000..1cca9e039a
--- /dev/null
+++ b/tests/basics/tests/try2.py
@@ -0,0 +1,12 @@
+# nested try's
+
+try:
+ print("try 1")
+ try:
+ print("try 2")
+ foo()
+ except:
+ print("except 2")
+ bar()
+except:
+ print("except 1")
diff --git a/tests/basics/tests/try3.py b/tests/basics/tests/try3.py
new file mode 100644
index 0000000000..31bacd3b36
--- /dev/null
+++ b/tests/basics/tests/try3.py
@@ -0,0 +1,17 @@
+# nested exceptions
+
+def f():
+ try:
+ foo()
+ except:
+ print("except 1")
+ try:
+ baz()
+ except:
+ print("except 2")
+ bar()
+
+try:
+ f()
+except:
+ print("f except")
diff --git a/tests/basics/tests/try4.py b/tests/basics/tests/try4.py
new file mode 100644
index 0000000000..4d324c1876
--- /dev/null
+++ b/tests/basics/tests/try4.py
@@ -0,0 +1,21 @@
+# triple nested exceptions
+
+def f():
+ try:
+ foo()
+ except:
+ print("except 1")
+ try:
+ bar()
+ except:
+ print("except 2")
+ try:
+ baz()
+ except:
+ print("except 3")
+ bak()
+
+try:
+ f()
+except:
+ print("f except")
diff --git a/tests/basics/tests/while1.py b/tests/basics/tests/while1.py
new file mode 100644
index 0000000000..a9bb5d2792
--- /dev/null
+++ b/tests/basics/tests/while1.py
@@ -0,0 +1,12 @@
+# basic while loop
+
+x = 0
+while x < 2:
+ y = 0
+ while y < 2:
+ z = 0
+ while z < 2:
+ z = z + 1
+ print(x, y, z)
+ y = y + 1
+ x = x + 1