Skip to content
This repository has been archived by the owner on Jun 12, 2023. It is now read-only.

Commit

Permalink
Merge pull request #6 from spectral-lab/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
szk2s authored May 29, 2019
2 parents 941f0c5 + 9ed4c79 commit 8406feb
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 28 deletions.
64 changes: 40 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
> Utility library which helps Test Driven Development in Cycling '74 Max
## What is TDD?
See [Wikipedia](https://en.wikipedia.org/wiki/Test-driven_development)
- Test Driven Development
- “Test-First” approach in which unit tests are written before code or patcher
- See [Wikipedia](https://en.wikipedia.org/wiki/Test-driven_development)
## Why TDD is important?
The importance of TDD cannot be overemphasized.
TDD means fewer bugs, higher quality software, and a razor focus, but it can slow development down and the test suites can be tedious to manage and maintain.
All in all, it is a recommended approach as the Pros far outweighs the Cons.
See [this article](https://medium.com/@gondy/the-importance-of-test-driven-development-f80b0d02edd8)
- TDD means fewer bugs, higher quality software, and a razor focus.
- TDD allows problems to be detected as early as possible
- See [this article](https://medium.com/@gondy/the-importance-of-test-driven-development-f80b0d02edd8)

## Install
1. Download zip file from [release page](https://github.com/spectral-lab/TDD-Max/releases)
Expand All @@ -19,36 +20,51 @@
## Usage
To use TDD-Max, you need to prepare two things, "test patcher" and "test code"
### Test patcher
You can make your test patcher as shown below. If you would like to use this as your template, this is accessible from the help patcher.
You can make your test patcher as shown below. If you would like to use this as your template, this is accessible in the help patcher.

<img width="1440" alt="Screen Shot 2019-05-29 at 18 11 32" src="https://user-images.githubusercontent.com/31060964/58545345-054c9900-823e-11e9-952e-21e33690fa07.png">

### Test codes
Here is an example of how you can write your test codes.
```js
const assert = require('chai').assert;

module.exports = {
target: 'add1',
testAdd1: function*(maxAPI) {
maxAPI.outlet({ add1: 3 });
assert.equal(yield, 4, 'ordinary int');
maxAPI.outlet({ add1: 0.1 });
assert.equal(yield, 1.1, 'float val');
maxAPI.outlet({ add1: 100000 });
assert.equal(yield, 100001, 'big int');
maxAPI.outlet({ add1: -2.1 });
assert.equal(yield, -1.1, 'negative float');
// Name of the patcher which you want to test
target: 'sum',

// `initPatcher` will be executed just before each test function.
initPatcher: function*(maxAPI) {
maxAPI.outlet({ sum: { inlet0: 0.0, inlet1: 0.0 } });
assert.notEqual(yield, null, 'isOk');
},

// The key of each test generator function should start with 'test'
testSumTwoNumbers: function*(maxAPI) {
maxAPI.outlet({ sum: { inlet0: 1, inlet1: 2 } });
assert.equal(yield, 3, 'ordinary int');
maxAPI.outlet({ sum: { inlet0: 0.1, inlet1: 0.2 } });
assert.equal(yield, 0.3, 'float val');
},
testWithoutRightInlet: function*(maxAPI) {
maxAPI.outlet({ sum: { inlet0: -1.2 } });
assert.equal(yield, -1.2, 'ordinary int');
}
};

```
More example codes can be found at https://github.com/spectral-lab/TDD-Max/tree/master/example
More example codes can be found at [example folder](https://github.com/spectral-lab/TDD-Max/tree/master/example)

Be careful that all your test codes should be named as `*.test.js`.
In addition, you must place your test code in the same folder as your test patcher. Or, the subfolder can be used.
`tdd` will search those folders and load your codes automatically even if you have multiple test files.

If you'd like to use some assertion library such as 'chai', please be aware those libraries should be installed to your project root, not to the folder where the `tdd` patcher is installed. Sending `npm install` message to `tdd` patcher will not work, so please use the command line.
#### Notes
- Test codes should be named as `*.test.js`.
- Test codes sould be placed in the same folder as your test patcher. You can also use subfolders.
- - `tdd` will search those folders and load your codes automatically even if you have multiple test files.

#### Dependencies of your test codes
If you'd like to use some assertion library such as 'chai', please be aware those libraries should be installed to your project root, not to the folder where the TDD-Max is installed. Sending `npm install chai` message to `tdd` patcher will not work, so please use the command line.

#### Generator function
If you are not familiar to `generator function`, please see the [MDN web docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function*).

If you are not familiar to `generator function`, please see the [MDN web docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function*).
## PR is welcome!
You can file an issue, but PR is greatly appreciated. The code is simple enough to modify quickly.
Though you can file an issue, PR is much more appreciated. The code is simple enough to modify quickly.
4 changes: 0 additions & 4 deletions example/code/sum.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ module.exports = {
assert.equal(yield, 3, 'ordinary int');
maxAPI.outlet({ sum: { inlet0: 0.1, inlet1: 0.2 } });
assert.equal(yield, 0.3, 'float val');
maxAPI.outlet({ sum: { inlet0: 5000, inlet1: 8000 } });
assert.equal(yield, 13000, 'big int');
maxAPI.outlet({ sum: { inlet0: -1, inlet1: -4 } });
assert.equal(yield, -5, 'negative int');
},
testWithoutRightInlet: function*(maxAPI) {
maxAPI.outlet({ sum: { inlet0: -1.2 } });
Expand Down

0 comments on commit 8406feb

Please sign in to comment.