get tests working

This commit is contained in:
alex 2022-01-23 16:41:37 +00:00
parent 40f2355fbf
commit 615d441381
5 changed files with 8215 additions and 28 deletions

View File

View File

@ -30,7 +30,7 @@ class TimeSpan {
while (end.gt(begin)) { while (end.gt(begin)) {
// If begin and end are in the same cycle, we're done. // If begin and end are in the same cycle, we're done.
if (begin.sam() == end_sam) { if (begin.sam().equals(end_sam)) {
spans.push(new TimeSpan(begin, this.end)) spans.push(new TimeSpan(begin, this.end))
break break
} }
@ -73,7 +73,7 @@ class TimeSpan {
intersection_e(other) { intersection_e(other) {
// Like 'sect', but raises an exception if the timespans don't intersect. // Like 'sect', but raises an exception if the timespans don't intersect.
result = this.intersection(other) result = this.intersection(other)
if (result == None) { if (result.equals(None)) {
// TODO - raise exception // TODO - raise exception
// raise ValueError(f'TimeSpan {self} and TimeSpan {other} do not intersect') // raise ValueError(f'TimeSpan {self} and TimeSpan {other} do not intersect')
} }
@ -89,7 +89,7 @@ class TimeSpan {
} }
} }
class Event { class Hap {
/* /*
Event class, representing a value active during the timespan Event class, representing a value active during the timespan
@ -111,28 +111,19 @@ class Event {
with_span(func) { with_span(func) {
// Returns a new event with the function f applies to the event timespan. // Returns a new event with the function f applies to the event timespan.
var whole = this.whole ? func(self.whole) : undefined var whole = this.whole ? func(self.whole) : undefined
return new Event(whole, func(this.part), this.value) return new Hap(whole, func(this.part), this.value)
} }
with_value(func) { with_value(func) {
// Returns a new event with the function f applies to the event value. // Returns a new event with the function f applies to the event value.
return new Event(this.whole, this.part, func(this.value)) return new Hap(this.whole, this.part, func(this.value))
} }
has_onset() { has_onset() {
// Test whether the event contains the onset, i.e that // Test whether the event contains the onset, i.e that
// the beginning of the part is the same as that of the whole timespan.""" // the beginning of the part is the same as that of the whole timespan."""
return (this.whole != undefined) && (this.whole.begin == this.part.begin) return (this.whole != undefined) && (this.whole.begin.equals(this.part.begin))
} }
} }
window.bar = function() { export {TimeSpan, Hap}
console.log("aha" + typeof(Fraction(3.5)));
}
//console.log((new TimeSpan(3.5,4)).midpoint);
var ts = new TimeSpan(0,4)
console.log((new Event(new TimeSpan(0,2), new TimeSpan(0,2), "aha")).has_onset());
var x = new TimeSpan(0,4)
console.log(ts.equals(x))

8191
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -24,6 +24,10 @@
}, },
"homepage": "https://github.com/yaxu/strudel#readme", "homepage": "https://github.com/yaxu/strudel#readme",
"devDependencies": { "devDependencies": {
"fraction.js": "^4.1.2" "fraction.js": "^4.1.2",
"mocha": "^9.1.4"
},
"dependencies": {
"snowpack": "^3.8.8"
} }
} }

23
test/pattern.test.mjs Normal file
View File

@ -0,0 +1,23 @@
import 'fraction.js';
import { strict as assert } from 'assert';
import {TimeSpan, Hap} from "../js/strudel.mjs";
describe('TimeSpan', function() {
describe('equal()', function() {
it('Should be equal to the same value', function() {
assert.equal((new TimeSpan(0,4)).equals(new TimeSpan(0,4)), true);
});
});
});
describe('Hap', function() {
describe('has_onset()', function() {
it('True if part includes onset from whole', function() {
assert.equal(new Hap(new TimeSpan(0,1), new TimeSpan(0,1), "thing").has_onset(), true);
});
});
});