Commit a6a0b5f2 authored by Grand Francois's avatar Grand Francois
Browse files

ajout de tests unitaires pour ParamValues/ParamValueIterator

Showing with 148 additions and 0 deletions
+148 -0
/// <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]);
});
});
/// <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();
});
});
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment