rev 521 - trunk/pr/test
SVN User <[email protected]> Thu, 20 May 2004 19:44:30 -0400
| Newsgroups | gmane.comp.lang.prothon.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: mark
Date: 2004-05-20 19:44:27 -0400 (Thu, 20 May 2004)
New Revision: 521
Added:
trunk/pr/test/mi2.pr
Modified:
trunk/pr/test/test.pr
Log:
added test/mi2.pr
Added: trunk/pr/test/mi2.pr
===================================================================
--- trunk/pr/test/mi2.pr 2004-05-20 23:17:39 UTC (rev 520)
+++ trunk/pr/test/mi2.pr 2004-05-20 23:44:27 UTC (rev 521)
@@ -0,0 +1,53 @@
+#!/usr/bin/env prothon
+
+def refer(start, attrname):
+ mro = self.protoList()
+ n = mro.len()
+ i = 0
+ while i < n:
+ if mro[i] is start:
+ break
+ i += 1
+ if i == n:
+ raise AttributeError
+ while True:
+ i += 1
+ if i == n:
+ break
+ o = mro[i]
+ attrs = o.attrs()
+ if attrname in attrs:
+ a = attrs[attrname]
+ if a.hasProto?(Func):
+ return a
+ return a
+ raise AttributeError
+
+object ModInt(Int):
+ modulo = 10
+ def call_(i=0):
+ call = refer(ModInt, 'call_')
+ return call{self}(i % self.modulo)
+
+ def add_(other):
+ if self.modulo != other.modulo:
+ raise TypeError
+ proto = self.protoList()[1]
+ add = refer(ModInt, 'add_')
+ x = proto(add{self}(other))
+ return x
+
+object Mod8Int(ModInt):
+ modulo = 8
+
+m = Mod8Int(0)
+n = Mod8Int(1)
+for i in 100:
+ if m != i % 8:
+ print "test failed:",i
+ Sys.exit(1)
+ m = m + n
+
+print """
+All tests passed
+"""
Property changes on: trunk/pr/test/mi2.pr
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: trunk/pr/test/test.pr
===================================================================
--- trunk/pr/test/test.pr 2004-05-20 23:17:39 UTC (rev 520)
+++ trunk/pr/test/test.pr 2004-05-20 23:44:27 UTC (rev 521)
@@ -23,7 +23,6 @@
return a
raise AttributeError
-print "# 1) Integers that support modular addition:"
object ModInt(Int):
modulo = 10
def call_(i=0):
@@ -44,7 +43,12 @@
m = Mod8Int(1)
n = Mod8Int(1)
-print "%i, %s" % (m, m.protoList().str_())
for i in 1000:
m = m + n
- print "%i, %s" % (m, m.protoList().str_())
+ if (m != i % 8):
+ print "test failed:",i
+ Sys.exit(1)
+
+print """
+All tests passed
+"""