summaryrefslogtreecommitdiff
path: root/sources
diff options
context:
space:
mode:
authorburaq <buraq@epfl.ch>2003-05-06 15:25:56 +0000
committerburaq <buraq@epfl.ch>2003-05-06 15:25:56 +0000
commitf6ca2753186f35d418b45eea4bf962ce50bd3f0c (patch)
treea96717b2ec6e83839560716f6b39f2abae0b1368 /sources
parent7099e17fb256720a84284086e2811416320905f4 (diff)
downloadscala-f6ca2753186f35d418b45eea4bf962ce50bd3f0c.tar.gz
scala-f6ca2753186f35d418b45eea4bf962ce50bd3f0c.tar.bz2
scala-f6ca2753186f35d418b45eea4bf962ce50bd3f0c.zip
All the power of unit testing condensed in a 3 ...
All the power of unit testing condensed in a 3 lines higher-order function. join the "I love Applications of Functional Programming" club.
Diffstat (limited to 'sources')
-rw-r--r--sources/scala/UnitTest.scala42
1 files changed, 42 insertions, 0 deletions
diff --git a/sources/scala/UnitTest.scala b/sources/scala/UnitTest.scala
new file mode 100644
index 0000000000..e5cefb94df
--- /dev/null
+++ b/sources/scala/UnitTest.scala
@@ -0,0 +1,42 @@
+package scala ;
+
+object UnitTest {
+
+ def test[b,a]( doit:b => a,
+ input: b,
+ expectedResult:a ):Unit = {
+
+ if( doit(input) == expectedResult )
+ {
+ System.out.println("passed ok")
+ }
+ else
+ {
+ System.out.print("failed! we got");
+ System.out.print( "\""+doit(input).toString()+"\"" );
+ System.out.println(" but expected "+expectedResult)
+ }
+
+ } // testAlg
+
+ def test2[c,b,a]( doit:(c,b) => a,
+ in1: c,
+ in2: b,
+ expectedResult:a ):Unit = {
+
+ if( doit(in1,in2) == expectedResult )
+ {
+ System.out.println("passed ok")
+ }
+ else
+ {
+ System.out.print("failed! we got");
+ System.out.print( "\""+doit(in1,in2).toString()+"\"" );
+ System.out.println(" but expected "+expectedResult)
+ }
+
+ } // testAlg
+
+} // unitTest
+
+