Now that we’ve made an impractical language, let’s stop the academic elitism and build something for the Real World™.
Automated testing is extremely important for finding bugs. Even for formally verified software. An example is automated unit testing, which tests an individual part of the code, such as a method:
assert(adder.add(1, 1) == 2);
Automated tests are generally written in the same language as the implementation code, in a separate module, using a test framework and test runner.
Despite its importance, testing is almost never the primary concern for language designers.
Until now.
The goal of this theme is to create a language that is somehow related to automated testing. This could be interpreted however you like, for example:
Go on and make testing better!
class Sum {
int add(int x, int y) { return x + y; }
unittest
{
Sum sum = new Sum;
assert(sum.add(3,4) == 7);
assert(sum.add(-2,0) == -2);
}
}
class Utils
shared
def countChars(s as String, c as char) as int
"""
Returns the number of instances of c in s.
"""
test
assert Utils.countChars('', c'x') == 0
assert Utils.countChars('x', c'x') == 1
assert Utils.countChars('X', c'x') == 0 # case sensitive
assert Utils.countChars(' ! ! ', c'!') == 2
body
count = 0
for ch in s
if c == ch
count += 1
return count
import noop.Console;
import noop.FakeConsole;
class HelloWorld(Console c) {
Int main(List args) {
c.println("Hello tests!");
return 1;
}
test "prints hello" scope (Console -> FakeConsole) {
main(List()) should equal(1);
c.asInstance(FakeConsole).getPrintedText() should contain("Hello tests!"));
}
}
Repo | User | Innovation | Completeness | Theme | Total |
---|---|---|---|---|---|
Testoy | mdg | 5 | 5 | 5 | 15 |
Vigil | munificent | 5 | 5 | 3 | 13 |
Bianca (archive) | aaditmshah | 4 | 4 | 4 | 12 |
PIPO | zayac | 4 | 4 | 4 | 12 |
symplex | greedy | 4 | 4 | 4 | 12 |
FORTHolito | tormaroe | 3 | 5 | 2 | 10 |
isitoq | gatesphere | 4 | 4 | 1 | 9 |
Banker | elitheeli | 2 | 4 | 2 | 8 |
constrained | fwg | 1 | 1 | 3 | 5 |
11rank | morefreeze | 1 | 1 | 1 | 3 |