Skip to content

Commit

Permalink
Add a test example to JavaScript
Browse files Browse the repository at this point in the history
  • Loading branch information
bkaestner committed Aug 12, 2015
1 parent dd3daeb commit e3366af
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
2 changes: 1 addition & 1 deletion rules/0220-Haskell.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ QuickCheck returns:
To prevent name clashes, only import what you need from the user module.
This enables the user to define additional helpers at global namespace.

### Test template
### Test example

``` haskell
module Codewars.MyPrefix.KataName.Test where
Expand Down
37 changes: 36 additions & 1 deletion rules/0230-JavaScript.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ so you probably edit the functions for your needs. Also note that
`generator` should return an array.

**NOTE:** The functions haven't been tested thoroughly. Use them with care
and feel free to edit them if they contain any errors.
and feel free to create an issue or a pull-request if they contain any errors.

``` javascript
/**
Expand Down Expand Up @@ -87,7 +87,9 @@ var randomAssertEquals = function(generator, userSol, refSol, tests){
}
}
}
```

``` javascript
/**
* @brief Tests a user defined function against a reference function.
* @param generator generates random arguments (must return an array)
Expand All @@ -114,3 +116,36 @@ var randomAssertSimilar = function(generator, userSol, refSol, tests){
}
}
```

### Test example

``` javascript
Test.describe("functionName1", function(){
var solution = function(){
// your solution
};
Test.it("should work for some simple examples", () => {
Test.assertEquals(functionName1("abc"), "abc");
Test.assertEquals(functionName1("xyz"), "xyz");
Test.assertEquals(functionName1("") , ""); // corner case
});

Test.it("should not return strings longer than 3 chars", () => {
for(let i = 0; i < 100; ++i){
const str = Test.randomToken();
Test.expect(functionName1(str).length <= 3,
'returned more than 3 characters on' + str);
}
});

Test.it("returns the correct string", () => {
for(let i = 0; i < 100; ++i){
const str = Test.randomToken();
Test.assertEquals(
functionName1(str),
solution(str)
);
}
});
});
```

0 comments on commit e3366af

Please sign in to comment.