diff --git a/spec/iterator/paramvalues_iterator.spec.ts b/spec/iterator/paramvalues_iterator.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..b92b76790b3116f423b8638b990bc6cb30ee7d47 --- /dev/null +++ b/spec/iterator/paramvalues_iterator.spec.ts @@ -0,0 +1,89 @@ +/// <reference path="../../node_modules/@types/jasmine/index.d.ts" /> + +import { ParamValues, ParamValueMode, ParamValueIterator } from "../../src/param/param-values" + +function checkNumberList(it: ParamValueIterator, exp: number[]) { + let n = 0; + for (const v of it) { + expect(v).toEqual(exp[n]); + n++; + } + expect(n).toEqual(exp.length); +} + +describe('paramvalues iterator : ', () => { + it("vide (1)", () => { + const p = new ParamValues(); + expect(() => p.getValuesIterator()).toThrow(new Error("ParamValueIterator : mode de génération de valeurs CALCUL incorrect")); + }); + + it("vide (2)", () => { + const p = new ParamValues(); + p.valueMode = ParamValueMode.SINGLE + expect(() => p.getValuesIterator()).toThrow(new Error("ParamValues : valeur fixe non définie")); + }); + + it("vide (3)", () => { + const p = new ParamValues(); + p.valueMode = ParamValueMode.MINMAX + expect(() => p.getValuesIterator()).toThrow(new Error("ParamValues : valeur min non définie")); + }); + + it("vide (4)", () => { + const p = new ParamValues(); + p.valueMode = ParamValueMode.LISTE + expect(() => p.getValuesIterator()).toThrow(new Error("ParamValues : liste de valeurs non définie")); + }); + + it("single (1)", () => { + const p = new ParamValues(); + p.setValues(0); + const it = p.getValuesIterator(); + expect(it.hasNext).toBeTruthy(); + const n1 = it.next(); + expect(n1.value).toEqual(0); + expect(n1.done).toBeFalsy(); + expect(it.hasNext).toBeFalsy(); + const n2 = it.next(); + expect(n2.value).toBeUndefined(); + expect(n2.done).toBeTruthy(); + }); + + it("single (2)", () => { + const p = new ParamValues(); + p.setValues(0); + checkNumberList(p.getValuesIterator(), [0]); + }); + + it("minmax (1)", () => { + const p = new ParamValues(); + p.setValues(0, 1, 2); + checkNumberList(p.getValuesIterator(), [0]); + }); + + it("minmax (2)", () => { + const p = new ParamValues(); + p.setValues(0, 1, 0.5); + checkNumberList(p.getValuesIterator(), [0, 0.5, 1]); + }); + + it("liste (1)", () => { + const p = new ParamValues(); + p.setValues([]); + const it = p.getValuesIterator(); + expect(it.next().done).toBeTruthy(); + checkNumberList(p.getValuesIterator(), []); + }); + + it("liste (2)", () => { + const p = new ParamValues(); + p.setValues([0]); + checkNumberList(p.getValuesIterator(), [0]); + }); + + it("liste (3)", () => { + const p = new ParamValues(); + p.setValues([1, 0.1]); + checkNumberList(p.getValuesIterator(), [1, 0.1]); + }); +}); diff --git a/spec/param/param-values.spec.ts b/spec/param/param-values.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..6c155989e9fdb919037646bd4ab6f37d780b97f3 --- /dev/null +++ b/spec/param/param-values.spec.ts @@ -0,0 +1,59 @@ +/// <reference path="../../node_modules/@types/jasmine/index.d.ts" /> + +import { ParamValues, ParamValueMode } from "../../src/param/param-values" + +describe('paramvalues : ', () => { + it("check single (1)", () => { + const p = new ParamValues(); + p.valueMode = ParamValueMode.SINGLE; + expect(() => p.check()).toThrow(); + }); + + it("check single (1)", () => { + const p = new ParamValues(); + p.setValues(0) + expect(() => p.check()).not.toThrow(); + }); + + it("check minmax (1)", () => { + const p = new ParamValues(); + p.valueMode = ParamValueMode.MINMAX; + expect(() => p.check()).toThrow(); + }); + + it("check minmax (2)", () => { + const p = new ParamValues(); + p.setValues(0, -1, 1) + expect(() => p.check()).toThrow(); + }); + + it("check minmax (3)", () => { + const p = new ParamValues(); + p.setValues(0, 1, 1) + expect(() => p.check()).not.toThrow(); + }); + + it("check liste (1)", () => { + const p = new ParamValues(); + p.valueMode = ParamValueMode.LISTE; + expect(() => p.check()).toThrow(); + }); + + it("check liste (2)", () => { + const p = new ParamValues(); + p.setValues([]) + expect(() => p.check()).not.toThrow(); + }); + + it("check liste (3)", () => { + const p = new ParamValues(); + p.setValues([0]) + expect(() => p.check()).not.toThrow(); + }); + + it("check calcul (1)", () => { + const p = new ParamValues(); + p.valueMode = ParamValueMode.CALCUL; + expect(() => p.check()).not.toThrow(); + }); +});