Skip to content

Commit f6ca275

Browse files
author
buraq
committed
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.
1 parent 7099e17 commit f6ca275

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

sources/scala/UnitTest.scala

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package scala ;
2+
3+
object UnitTest {
4+
5+
def test[b,a]( doit:b => a,
6+
input: b,
7+
expectedResult:a ):Unit = {
8+
9+
if( doit(input) == expectedResult )
10+
{
11+
System.out.println("passed ok")
12+
}
13+
else
14+
{
15+
System.out.print("failed! we got");
16+
System.out.print( "\""+doit(input).toString()+"\"" );
17+
System.out.println(" but expected "+expectedResult)
18+
}
19+
20+
} // testAlg
21+
22+
def test2[c,b,a]( doit:(c,b) => a,
23+
in1: c,
24+
in2: b,
25+
expectedResult:a ):Unit = {
26+
27+
if( doit(in1,in2) == expectedResult )
28+
{
29+
System.out.println("passed ok")
30+
}
31+
else
32+
{
33+
System.out.print("failed! we got");
34+
System.out.print( "\""+doit(in1,in2).toString()+"\"" );
35+
System.out.println(" but expected "+expectedResult)
36+
}
37+
38+
} // testAlg
39+
40+
} // unitTest
41+
42+

0 commit comments

Comments
 (0)