From ba1ad77b47bc8d00ce840b99844089c590d4856c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois=20Grand?= <francois.grand@inrae.fr>
Date: Fri, 17 Mar 2023 16:15:21 +0100
Subject: [PATCH] refactor(test): rework CreateTestNub() with switch case

refs #325
---
 spec/fuzzing.spec.ts | 73 +++++++++++++++++++++++++-------------------
 1 file changed, 42 insertions(+), 31 deletions(-)

diff --git a/spec/fuzzing.spec.ts b/spec/fuzzing.spec.ts
index 6642d0c0..bcb03bbf 100644
--- a/spec/fuzzing.spec.ts
+++ b/spec/fuzzing.spec.ts
@@ -225,38 +225,49 @@ function CreateTestNub(iCalType: number): Nub {
     if (nubsWithPressureLossLaw.includes(iCalType)) {
         setRandomPressureLossLaw(n as PressureLoss);
     }
-    if (iCalType === CalculatorType.CourbeRemous) {
-        n.setPropValue(
-            "methodeResolution",
-            Math.floor(Math.random() * 3) // Euler, RK4, Trapèzes
-        );
-    }
-    if (iCalType === CalculatorType.Pab) {
-        setPab(n as Pab, fuzzyCfg.Pab.poolMax, fuzzyCfg.Pab.structureMax);
-    }
-    if (iCalType === CalculatorType.MacroRugoCompound) {
-        setMacrorugoCompound(n as MacrorugoCompound);
-    }
-    if (iCalType === CalculatorType.Grille) {
-        setGrille(n as Grille);
-    }
-    if (iCalType === CalculatorType.Bief) {
-        setRandomSection(n as SectionNub);
-    }
-    if (iCalType === CalculatorType.Trigo) {
-        setRandomTrigoOperation(n as Trigo);
-        setRandomTrigoUnit(n as Trigo);
-    }
-    if (iCalType === CalculatorType.SPP) {
-        addRandomYAXNs(n as SPP);
-        setRandomSppOperation(n as SPP);
-    }
-    if (iCalType === CalculatorType.Par) {
-        setRandomParType(n as Par);
-    }
-    if (iCalType === CalculatorType.ParSimulation) {
-        setRandomParType(n as ParSimulation);
+    switch (iCalType) {
+        case CalculatorType.CourbeRemous:
+            n.setPropValue(
+                "methodeResolution",
+                Math.floor(Math.random() * 3) // Euler, RK4, Trapèzes
+            );
+            break;
+
+        case CalculatorType.Pab:
+            setPab(n as Pab, fuzzyCfg.Pab.poolMax, fuzzyCfg.Pab.structureMax);
+            break;
+
+        case CalculatorType.MacroRugoCompound:
+            setMacrorugoCompound(n as MacrorugoCompound);
+            break;
+
+        case CalculatorType.Grille:
+            setGrille(n as Grille);
+            break;
+
+        case CalculatorType.Bief:
+            setRandomSection(n as SectionNub);
+            break;
+
+        case CalculatorType.Trigo:
+            setRandomTrigoOperation(n as Trigo);
+            setRandomTrigoUnit(n as Trigo);
+            break;
+
+        case CalculatorType.SPP:
+            addRandomYAXNs(n as SPP);
+            setRandomSppOperation(n as SPP);
+            break;
+
+        case CalculatorType.Par:
+            setRandomParType(n as Par);
+            break;
+
+        case CalculatorType.ParSimulation:
+            setRandomParType(n as ParSimulation);
+            break;
     }
+
     for (const p of n.parameterIterator) {
         if (p.visible) {
             randomizeParameter(p);
-- 
GitLab