From fc68250b2b0f62573f55cc3e23edc38bd5cac906 Mon Sep 17 00:00:00 2001
From: "francois.grand" <francois.grand@irstea.fr>
Date: Thu, 1 Jun 2017 16:18:53 +0200
Subject: [PATCH] =?UTF-8?q?tests=20unitaires=20r=C3=A9gime=20uniforme/sect?=
 =?UTF-8?q?ion=20circulaire?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 Makefile                          |   5 +-
 spec/base.spec.ts                 |   9 +--
 spec/nubtest.ts                   |   6 +-
 spec/regime_uniforme_circ.spec.ts | 117 ++++++++++++++++++++++++++++++
 src/nub.ts                        |   4 +
 src/regime_uniforme.ts            |   4 +-
 6 files changed, 132 insertions(+), 13 deletions(-)
 create mode 100644 spec/regime_uniforme_circ.spec.ts

diff --git a/Makefile b/Makefile
index e94987b7..e3e6ff5e 100644
--- a/Makefile
+++ b/Makefile
@@ -20,11 +20,14 @@ build-dir :
 buildspec :
 	npm run buildspec
 
-jasmine : buildspec
+jasmine : buildspec cls
 	npm run jasmine
 
 karma :
 	npm run karma
 
+cls :
+	printf "\033c"
+
 clean :
 	rm -rf $(BUILD_DIR)
diff --git a/spec/base.spec.ts b/spec/base.spec.ts
index 0bb55fbd..0d4d9af8 100644
--- a/spec/base.spec.ts
+++ b/spec/base.spec.ts
@@ -10,16 +10,13 @@ describe('Class Nub: ', () => {
     // });
     describe('Calc(): ', () => {
         it('should return a result.vCalc equal to 3', () => {
-            let res = new Result(3);
-            expect(nub.Calc("C").vCalc).toBeCloseTo(res.vCalc, precDigits);
+            expect(nub.Calc("C").vCalc).toBeCloseTo(3, precDigits);
         });
         it('should return a result.vCalc equal to 1', () => {
-            let res = new Result(1);
-            expect(nub.Calc("A").vCalc).toBeCloseTo(res.vCalc, precDigits);
+            expect(nub.Calc("A").vCalc).toBeCloseTo(1, precDigits);
         });
         it('should return a result.vCalc equal to 2', () => {
-            let res = new Result(2); precDigits
-            expect(nub.Calc("B").vCalc).toBeCloseTo(res.vCalc, precDigits);
+            expect(nub.Calc("B").vCalc).toBeCloseTo(2, precDigits);
         });
     });
 });
diff --git a/spec/nubtest.ts b/spec/nubtest.ts
index 64a2f4f8..e6a32d2a 100644
--- a/spec/nubtest.ts
+++ b/spec/nubtest.ts
@@ -2,8 +2,8 @@ import { Result, IParamsEquation } from "../src/base";
 import { Nub } from "../src/nub";
 
 export class NubTest extends Nub {
-    constructor(v: IParamsEquation) {
-        super(v);
+    constructor(v: IParamsEquation, dbg: boolean = false) {
+        super(v, dbg);
         this.sVarsEq = ["C"];
     }
     Equation(): Result {
@@ -23,4 +23,4 @@ export let precDigits = 3;
 /**
  * précision de calcul (max de abs(v-v'))
  */
-export let precDist = Math.pow(10, -precDigits);
+export let precDist: number = Math.pow(10, -precDigits);
diff --git a/spec/regime_uniforme_circ.spec.ts b/spec/regime_uniforme_circ.spec.ts
new file mode 100644
index 00000000..3b48f312
--- /dev/null
+++ b/spec/regime_uniforme_circ.spec.ts
@@ -0,0 +1,117 @@
+/// <reference path="../node_modules/@types/jasmine/index.d.ts" />
+
+import { Result } from "../src/base";
+import { RegimeUniforme } from "../src/regime_uniforme";
+import { cSnCirc } from "../src/section/section_circulaire";
+import { cParamsCanal } from "../src/section/section_type";
+import { precDigits, precDist } from "./nubtest";
+
+describe('Class RegimeUniforme / section circulaire : ', () => {
+    // beforeAll(() => {
+    // });
+
+    describe('Calc(): ', () => {
+        it('Diamètre should be 6', () => {
+            let paramCnl = new cParamsCanal(40, //  Ks=Strickler
+                1.2,  //  Q=Débit
+                0.001, //  If=pente du fond
+                precDist, // précision
+                1 // YB= hauteur de berge
+                // YCL=Condition limite en cote à l'amont ou à l'aval
+            );
+
+            let sect = new cSnCirc(undefined, paramCnl,
+                0 // diamètre
+            );
+            // tirant d'eau
+            sect.v.Y = 0.6613;
+
+            let ru = new RegimeUniforme(sect);
+
+            // expect(ru.Calc("D", 0, 0.001).vCalc).toBeCloseTo(6, 2);
+            expect(ru.Calc("D").vCalc).toBeCloseTo(6, 2);
+        });
+
+
+        it('Ks should be 40', () => {
+            let paramCnl = new cParamsCanal(0, //  Ks=Strickler
+                1.2,  //  Q=Débit
+                0.001, //  If=pente du fond
+                precDist, // précision
+                1 // YB= hauteur de berge
+                // YCL=Condition limite en cote à l'amont ou à l'aval
+            );
+
+            let sect = new cSnCirc(undefined, paramCnl,
+                6 // diamètre
+            );
+            // tirant d'eau
+            sect.v.Y = 0.6613;
+
+            let ru = new RegimeUniforme(sect);
+
+            expect(ru.Calc("Ks").vCalc).toBeCloseTo(40, 2);
+        });
+
+
+        it('If should be 0.001', () => {
+            let paramCnl = new cParamsCanal(40, //  Ks=Strickler
+                1.2,  //  Q=Débit
+                0, //  If=pente du fond
+                precDist, // précision
+                1 // YB= hauteur de berge
+                // YCL=Condition limite en cote à l'amont ou à l'aval
+            );
+
+            let sect = new cSnCirc(undefined, paramCnl,
+                6 // diamètre
+            );
+            // tirant d'eau
+            sect.v.Y = 0.6613;
+
+            let ru = new RegimeUniforme(sect);
+
+            expect(ru.Calc("If").vCalc).toBeCloseTo(0.001, precDigits);
+        });
+
+        it('Q should be 1.2', () => {
+            let paramCnl = new cParamsCanal(40, //  Ks=Strickler
+                0,  //  Q=Débit
+                0.001, //  If=pente du fond
+                precDist, // précision
+                1 // YB= hauteur de berge
+                // YCL=Condition limite en cote à l'amont ou à l'aval
+            );
+
+            let sect = new cSnCirc(undefined, paramCnl,
+                6 // diamètre
+            );
+            // tirant d'eau
+            sect.v.Y = 0.6613;
+
+            let ru = new RegimeUniforme(sect);
+
+            expect(ru.Calc("Q").vCalc).toBeCloseTo(1.2, precDigits);
+        });
+
+        it('Y should be 0.6613', () => {
+            let paramCnl = new cParamsCanal(40, //  Ks=Strickler
+                1.2,  //  Q=Débit
+                0.001, //  If=pente du fond
+                precDist, // précision
+                1 // YB= hauteur de berge
+                // YCL=Condition limite en cote à l'amont ou à l'aval
+            );
+
+            let sect = new cSnCirc(undefined, paramCnl,
+                6 // diamètre
+            );
+            // tirant d'eau
+            sect.v.Y = 0;
+
+            let ru = new RegimeUniforme(sect);
+
+            expect(ru.Calc("Y").vCalc).toBeCloseTo(0.6613, precDigits);
+        });
+    });
+});
diff --git a/src/nub.ts b/src/nub.ts
index 0b8be8df..e6a257e0 100644
--- a/src/nub.ts
+++ b/src/nub.ts
@@ -29,6 +29,10 @@ export abstract class Nub extends Debug {
      * @param rPrec précision de calcul
      */
     Calc(sVarCalc: string, rInit: number = 0, rPrec: number = 0.001): Result {
+        this.debug("nub : sVarCalc=" + sVarCalc);
+        this.debug("nub : rInit=" + rInit);
+        this.debug("nub : rPrec=" + rPrec);
+
         for (let sVarEq of this._varsEq) {
             if (sVarCalc == sVarEq) {
                 return this.Equation(sVarCalc);
diff --git a/src/regime_uniforme.ts b/src/regime_uniforme.ts
index fa8cf789..bee2efa5 100644
--- a/src/regime_uniforme.ts
+++ b/src/regime_uniforme.ts
@@ -10,8 +10,6 @@ export class RegimeUniforme extends Nub {
     constructor(s: acSection, dbg: boolean = false) {
         super(s.v, dbg);
 
-        this.debug('constructeur RU');
-
         this.Sn = s;
 
         this.AddVarEq("Q");
@@ -29,7 +27,7 @@ export class RegimeUniforme extends Nub {
             //this.oLog.Add('h_normale_pente_neg_nul',true);
         } else {
             Qn = this.Sn.oP.v.Ks * Math.pow(this.Sn.Calc('R', this.Sn.v.Y), 2 / 3) * this.Sn.Calc('S', this.Sn.v.Y) * Math.sqrt(this.Sn.oP.v.If);
-            this.debug("RU : Qn=" + Qn);
+            //this.debug("RU : Qn=" + Qn);
         }
         return Qn;
     }
-- 
GitLab