From a6a0b5f28d59f7ee19516ab639bacaba75d50791 Mon Sep 17 00:00:00 2001
From: "francois.grand" <francois.grand@irstea.fr>
Date: Wed, 28 Mar 2018 13:25:49 +0200
Subject: [PATCH] ajout de tests unitaires pour ParamValues/ParamValueIterator

---
 spec/iterator/paramvalues_iterator.spec.ts | 89 ++++++++++++++++++++++
 spec/param/param-values.spec.ts            | 59 ++++++++++++++
 2 files changed, 148 insertions(+)
 create mode 100644 spec/iterator/paramvalues_iterator.spec.ts
 create mode 100644 spec/param/param-values.spec.ts

diff --git a/spec/iterator/paramvalues_iterator.spec.ts b/spec/iterator/paramvalues_iterator.spec.ts
new file mode 100644
index 00000000..b92b7679
--- /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 00000000..6c155989
--- /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();
+    });
+});
-- 
GitLab