Skip to content

Commit

Permalink
Merge pull request #3 from LisiLisenok/develop
Browse files Browse the repository at this point in the history
0.4.0
  • Loading branch information
LisiLisenok committed Mar 5, 2016
2 parents d9b957e + 0da66d8 commit 4e1b9bc
Show file tree
Hide file tree
Showing 43 changed files with 2,742 additions and 936 deletions.
5 changes: 4 additions & 1 deletion .ceylon/config
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
[compiler]
source=source
resource=resource
source=examples
source=examples

[defaults]
encoding=UTF-8

[formattool]
profile=my
4 changes: 4 additions & 0 deletions .ceylon/config~
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
[compiler]
source=source
resource=resource
source=examples

[defaults]
encoding=UTF-8

[formattool]
profile=my
294 changes: 294 additions & 0 deletions .settings/org.eclipse.jdt.core.prefs

Large diffs are not rendered by default.

23 changes: 20 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,39 @@ is an extension to SDK `ceylon.test` module with following capabilities:
* executing tests concurrently or sequentially
* parameterized testing
* conditional test execution
* organizing complex test conditions into a one flexible expression with matchers
* multi-reporting, i.e. several failures or successes can be reported for a one particular test execution (test function)
* reporting test results using charts (or graphs)

The module is available on [CeylonHerd](https://herd.ceylon-lang.org/modules/herd.asynctest)



#### Ceylon compiler / platform

Compiled with Ceylon 1.2.1
Available on JVM only


#### Dependencies

* ceylon.collection/1.2.1
* ceylon.file/1.2.1
* ceylon.language/1.2.1
* ceylon.test/1.2.1 shared
* java.base/8 JDK


#### Usage and documentation

The extension is aimed to be run using Ceylon test tool.
See usage details in [API documentation](https://modules.ceylon-lang.org/repo/1/herd/asynctest/0.3.0/module-doc/api/index.html)
See usage details in [API documentation](https://modules.ceylon-lang.org/repo/1/herd/asynctest/0.4.0/module-doc/api/index.html)


#### Examples

* Test of [Fibonnachi numbers calculation](examples/herd/examples/asynctest/fibonnachi).
* Test of [Fibonacci numbers calculation](examples/herd/examples/asynctest/fibonacci).
Calculation function is executed on separated thread and returns results using `ceylon.promise`.
* [Time scheduler](examples/herd/examples/asynctest/scheduler) testing.
* [Microbenchmark](examples/herd/examples/asynctest/mapperformance) -
comparative performance test of Ceylon / Java HashMap and TreeMap.
* [Matchers](examples/herd/examples/asynctest/matchers) - mathcers usage.
75 changes: 75 additions & 0 deletions examples/herd/examples/asynctest/fibonacci/fibonacci.ceylon
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import ceylon.promise {

Deferred,
Promise
}
import java.lang {

Runnable,
Thread
}

"Calculates Fibonacci number by its index.
Function returns incorrect result in order to demonstrate test framework output.
"
throws( `class AssertionError`, "passed index of Fibonacci number `indexOfFibonacciNumber` is less or equals to zero" )
shared Integer positiveFibonacciNumber( Integer indexOfFibonacciNumber ) {
"Fibonnachi number index must be positive"
assert ( indexOfFibonacciNumber > 0 );
variable Integer n0 = 0;
variable Integer n1 = 1;
variable Integer ret = 1;
variable Integer currentIndex = 0; // use 1 to succeed the test!
while ( currentIndex < indexOfFibonacciNumber ) {
ret = n0 + n1;
n0 = n1;
n1 = ret;
currentIndex ++;
}
return ret;
}

"Calculates index of positive Fibonacci number. That's may not be correct for index 1 and 2,
which corresponds to equals Fibonacci numbers."
throws( `class AssertionError`, "passed `fibonacciNumber` is not a Fibonacci number" )
shared Integer fibonacciNumberIndex( Integer fibonacciNumber ) {
"fibonacci number must be positive"
assert ( fibonacciNumber > 0 );
variable Integer n0 = 0;
variable Integer n1 = 1;
variable Integer ret = 1;
variable Integer currentIndex = 1;
while ( ret < fibonacciNumber ) {
ret = n0 + n1;
n0 = n1;
n1 = ret;
currentIndex ++;
}
"passed `fibonacciNumber` is not a Fibonacci number"
assert ( ret == fibonacciNumber );
return currentIndex;
}


"Calculates Fibonacci number by its index in separated thread and returns result as promise.
This is function to be tested."
shared Promise<Integer> asyncPositiveFibonacciNumber( Integer indexOfFibonacciNumber ) {
Deferred<Integer> ret = Deferred<Integer>();

Thread th = Thread (
object satisfies Runnable {
shared actual void run() {
try {
ret.fulfill( positiveFibonacciNumber( indexOfFibonacciNumber ) );
}
catch ( Throwable err ) {
ret.reject( err );
}
}
}
);
th.start();

return ret.promise;
}

Original file line number Diff line number Diff line change
Expand Up @@ -12,47 +12,47 @@ import herd.asynctest {


"Fibonnachi test parameters."
see( `function runFibonnachiTest` )
{[Integer, Integer]*} fibonnachiNumbers =>
see( `function runFibonacciTest` )
{[Integer, Integer]*} fibonacciNumbers =>
{
[3, 2], [4, 3], [5, 5], [6, 8], [7, 13], [8, 21], [9, 34], [10, 55]
};


"Runs test of Fibonnachi numbers calculations.
"Runs test of Fibonacci numbers calculations.
Testing:
* comparison of expected value to calculated one
* comparison of calculated index of Fibonnachi number with passed one - this will fail if pass index `2`
* comparison of calculated index of Fibonacci number with passed one - this will fail if pass index `2`
The function is marked with `testExecutor` annotation in order to perform asynchronous test.
Alternatively `testExecutor` annotation can be used at module level."
test parameters( `value fibonnachiNumbers` )
test parameters( `value fibonacciNumbers` )
testExecutor( `class AsyncTestExecutor` )
shared void runFibonnachiTest (
shared void runFibonacciTest (
"Context to send test results." AsyncTestContext context,
"Index of fibonnachi number to be calculated." Integer indexOfFibonnachiNumber,
"Expected results of the calculations." Integer expectedFibonnachiNumber
"Index of fibonnachi number to be calculated." Integer indexOfFibonacciNumber,
"Expected results of the calculations." Integer expectedFibonacciNumber
) {
// starts testing on context
context.start();

// do testing procedure
asyncPositiveFibonnachiNumber( indexOfFibonnachiNumber ).completed (
( Integer calculatedFibonnachiNumber ) {
asyncPositiveFibonacciNumber( indexOfFibonacciNumber ).completed (
( Integer calculatedFibonacciNumber ) {
// compare calculated and expected values and notify context if fails
// Don't use `ceylon.test.assert...` here. It will throw on separated thread and will cause abnormal program termination
context.assertTrue (
calculatedFibonnachiNumber == expectedFibonnachiNumber,
"calculated Fibonnachi number ``calculatedFibonnachiNumber`` is not equal to expected one ``expectedFibonnachiNumber``",
calculatedFibonacciNumber == expectedFibonacciNumber,
"calculated Fibonacci number ``calculatedFibonacciNumber`` is not equal to expected one ``expectedFibonacciNumber``",
"number equality"
);

// calculates index from resulting Fibonnachi number and compare it with passed one
// calculates index from resulting Fibonacci number and compare it with passed one
try {
value index = fibonnachiNumberIndex( calculatedFibonnachiNumber );
value index = fibonacciNumberIndex( calculatedFibonacciNumber );
context.assertTrue (
index == indexOfFibonnachiNumber,
"calculated index of Fibonnachi number ``index`` is not equal to expected one ``indexOfFibonnachiNumber``",
index == indexOfFibonacciNumber,
"calculated index of Fibonacci number ``index`` is not equal to expected one ``indexOfFibonacciNumber``",
"index equality"
);
}
Expand All @@ -61,7 +61,7 @@ shared void runFibonnachiTest (
}

// completes the test when results reported
context.complete( "Fibonnachi number is ``calculatedFibonnachiNumber``" );
context.complete( "Fibonacci number is ``calculatedFibonacciNumber``" );
},
( Throwable reason ) {
// fail the test with error
Expand Down
7 changes: 7 additions & 0 deletions examples/herd/examples/asynctest/fibonacci/package.ceylon
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"
Testing of asynchronous calculation of Fibonacci numbers.
Test is performed on [[asyncPositiveFibonacciNumber]] using [[runFibonacciTest]] test function.
>Function [[positiveFibonacciNumber]] returns incorrect results in order to demonstrate test framework output.
"
by( "Lis" )
shared package herd.examples.asynctest.fibonacci;
75 changes: 0 additions & 75 deletions examples/herd/examples/asynctest/fibonnachi/fibonnachi.ceylon

This file was deleted.

7 changes: 0 additions & 7 deletions examples/herd/examples/asynctest/fibonnachi/package.ceylon

This file was deleted.

Loading

0 comments on commit 4e1b9bc

Please sign in to comment.