Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
cassiopee
jalhyd
Commits
ac786ba0
Commit
ac786ba0
authored
Oct 30, 2019
by
Mathias Chouet
🍝
Browse files
Add ParamFamily.ANY to make a parameter linkable to any visible param/result
parent
5378ee83
Changes
5
Hide whitespace changes
Inline
Side-by-side
spec/cond_distri.spec.ts
View file @
ac786ba0
import
{
YAXB
}
from
"
../src/axb
"
;
import
{
YAXBParams
}
from
"
../src/axb_params
"
;
import
{
MessageCode
}
from
"
../src/index
"
;
import
{
Session
}
from
"
../src/session
"
;
import
{
CreateStructure
}
from
"
../src/structure/factory_structure
"
;
import
{
ParallelStructure
}
from
"
../src/structure/parallel_structure
"
;
import
{
ParallelStructureParams
}
from
"
../src/structure/parallel_structure_params
"
;
import
{
LoiDebit
}
from
"
../src/structure/structure_props
"
;
import
{
MessageCode
}
from
"
../src/util/message
"
;
import
{
YAXB
}
from
"
../src/yaxb
"
;
import
{
YAXBParams
}
from
"
../src/yaxb_params
"
;
describe
(
"
Class YAXB:
"
,
()
=>
{
it
(
"
Y should be 10
"
,
()
=>
{
const
nub
=
new
YAXB
(
new
YAXBParams
(
666
,
2
,
3
,
4
));
nub
.
calculatedParam
=
nub
.
prms
.
Y
;
nub
.
CalcSerie
();
expect
(
nub
.
result
.
vCalc
).
toBe
(
10
);
});
describe
(
"
Calc:
"
,
()
=>
{
it
(
"
A
should be
2
"
,
()
=>
{
const
nub
=
new
YAXB
(
new
YAXBParams
(
10
,
666
,
3
,
4
));
nub
.
calculatedParam
=
nub
.
prms
.
A
;
nub
.
CalcSerie
();
expect
(
nub
.
result
.
vCalc
).
toBe
(
2
);
});
it
(
"
Y
should be
10
"
,
()
=>
{
const
nub
=
new
YAXB
(
new
YAXBParams
(
666
,
2
,
3
,
4
));
nub
.
calculatedParam
=
nub
.
prms
.
Y
;
nub
.
CalcSerie
();
expect
(
nub
.
result
.
vCalc
).
toBe
(
10
);
});
it
(
"
X
should be
3
"
,
()
=>
{
const
nub
=
new
YAXB
(
new
YAXBParams
(
10
,
2
,
666
,
4
));
nub
.
calculatedParam
=
nub
.
prms
.
X
;
nub
.
CalcSerie
();
expect
(
nub
.
result
.
vCalc
).
toBe
(
3
);
});
it
(
"
A
should be
2
"
,
()
=>
{
const
nub
=
new
YAXB
(
new
YAXBParams
(
10
,
666
,
3
,
4
));
nub
.
calculatedParam
=
nub
.
prms
.
A
;
nub
.
CalcSerie
();
expect
(
nub
.
result
.
vCalc
).
toBe
(
2
);
});
it
(
"
B should be 4
"
,
()
=>
{
const
nub
=
new
YAXB
(
new
YAXBParams
(
10
,
2
,
3
,
666
));
nub
.
calculatedParam
=
nub
.
prms
.
B
;
nub
.
CalcSerie
();
expect
(
nub
.
result
.
vCalc
).
toBe
(
4
);
});
it
(
"
X should be 3
"
,
()
=>
{
const
nub
=
new
YAXB
(
new
YAXBParams
(
10
,
2
,
666
,
4
));
nub
.
calculatedParam
=
nub
.
prms
.
X
;
nub
.
CalcSerie
();
expect
(
nub
.
result
.
vCalc
).
toBe
(
3
);
});
it
(
"
B should be 4
"
,
()
=>
{
const
nub
=
new
YAXB
(
new
YAXBParams
(
10
,
2
,
3
,
666
));
nub
.
calculatedParam
=
nub
.
prms
.
B
;
nub
.
CalcSerie
();
expect
(
nub
.
result
.
vCalc
).
toBe
(
4
);
});
it
(
"
calc A with X = 0 should trigger error
"
,
()
=>
{
const
nub
=
new
YAXB
(
new
YAXBParams
(
10
,
666
,
0
,
4
));
nub
.
calculatedParam
=
nub
.
prms
.
A
;
nub
.
CalcSerie
();
expect
(
nub
.
result
.
ok
).
toBe
(
false
);
expect
(
nub
.
result
.
resultElement
.
log
.
messages
.
length
).
toBe
(
1
);
expect
(
nub
.
result
.
resultElement
.
log
.
messages
[
0
].
code
).
toBe
(
MessageCode
.
ERROR_DIVISION_BY_ZERO
);
});
it
(
"
calc X with A = 0 should trigger error
"
,
()
=>
{
const
nub
=
new
YAXB
(
new
YAXBParams
(
10
,
0
,
666
,
4
));
nub
.
calculatedParam
=
nub
.
prms
.
X
;
nub
.
CalcSerie
();
expect
(
nub
.
result
.
ok
).
toBe
(
false
);
expect
(
nub
.
result
.
resultElement
.
log
.
messages
.
length
).
toBe
(
1
);
expect
(
nub
.
result
.
resultElement
.
log
.
messages
[
0
].
code
).
toBe
(
MessageCode
.
ERROR_DIVISION_BY_ZERO
);
});
it
(
"
calc A with X = 0 should trigger error
"
,
()
=>
{
const
nub
=
new
YAXB
(
new
YAXBParams
(
10
,
666
,
0
,
4
));
nub
.
calculatedParam
=
nub
.
prms
.
A
;
nub
.
CalcSerie
();
expect
(
nub
.
result
.
ok
).
toBe
(
false
);
expect
(
nub
.
result
.
resultElement
.
log
.
messages
.
length
).
toBe
(
1
);
expect
(
nub
.
result
.
resultElement
.
log
.
messages
[
0
].
code
).
toBe
(
MessageCode
.
ERROR_DIVISION_BY_ZERO
);
});
it
(
"
calc X with A = 0 should trigger error
"
,
()
=>
{
const
nub
=
new
YAXB
(
new
YAXBParams
(
10
,
0
,
666
,
4
));
nub
.
calculatedParam
=
nub
.
prms
.
X
;
nub
.
CalcSerie
();
expect
(
nub
.
result
.
ok
).
toBe
(
false
);
expect
(
nub
.
result
.
resultElement
.
log
.
messages
.
length
).
toBe
(
1
);
expect
(
nub
.
result
.
resultElement
.
log
.
messages
[
0
].
code
).
toBe
(
MessageCode
.
ERROR_DIVISION_BY_ZERO
);
describe
(
"
Link:
"
,
()
=>
{
it
(
"
all parameters must be linkable to Y,A,X,B in both ways
"
,
()
=>
{
const
yaxb
=
new
YAXB
(
new
YAXBParams
(
10
,
2
,
3
,
4
));
const
lo
=
new
ParallelStructure
(
new
ParallelStructureParams
(
1.2
,
102
,
101
));
lo
.
addChild
(
CreateStructure
(
LoiDebit
.
GateCem88d
,
lo
));
Session
.
getInstance
().
clear
();
Session
.
getInstance
().
registerNubs
([
yaxb
,
lo
]);
// each YAXB param should be linkable to all ParallelStructures params
expect
(
Session
.
getInstance
().
getLinkableValues
(
yaxb
.
prms
.
Y
).
length
).
toBe
(
7
);
expect
(
Session
.
getInstance
().
getLinkableValues
(
yaxb
.
prms
.
A
).
length
).
toBe
(
7
);
expect
(
Session
.
getInstance
().
getLinkableValues
(
yaxb
.
prms
.
X
).
length
).
toBe
(
7
);
expect
(
Session
.
getInstance
().
getLinkableValues
(
yaxb
.
prms
.
B
).
length
).
toBe
(
7
);
// each ParallelStructures param should be linkable to all YAXB params
for
(
const
p
of
lo
.
parameterIterator
)
{
expect
(
Session
.
getInstance
().
getLinkableValues
(
p
).
length
).
toBe
(
4
);
}
});
});
});
src/nub.ts
View file @
ac786ba0
...
...
@@ -602,10 +602,18 @@ export abstract class Nub extends ComputeNode implements IObservable {
// 1. own parameters
for
(
const
p
of
this
.
_prms
)
{
// if symbol and Nub type are identical
, or if family is identical
// if symbol and Nub type are identical
if
(
(
p
.
symbol
===
symbol
&&
this
.
calcType
===
src
.
nubCalcType
)
||
(
p
.
family
!==
undefined
&&
(
p
.
family
===
src
.
family
))
||
(
// or if family is identical
(
p
.
family
!==
undefined
&&
p
.
family
===
src
.
family
)
||
(
// or if one of the families is ANY and target parameter is visible
(
src
.
family
===
ParamFamily
.
ANY
||
p
.
family
===
ParamFamily
.
ANY
)
&&
p
.
visible
)
)
)
{
// if variability doesn't cause any problem (a non-variable
// parameter cannot be linked to a variating one)
...
...
@@ -645,9 +653,13 @@ export abstract class Nub extends ComputeNode implements IObservable {
// browse extra results
for
(
const
erSymbol
of
erk
)
{
const
erFamily
=
this
.
_resultsFamilies
[
erSymbol
];
// if family is identical and variability doesn't cause any problem
// if family is identical
or ANY,
and variability doesn't cause any problem
if
(
erFamily
===
src
.
family
(
erFamily
===
src
.
family
||
erFamily
===
ParamFamily
.
ANY
||
src
.
family
===
ParamFamily
.
ANY
)
&&
(
src
.
calculability
!==
ParamCalculability
.
FIXED
||
!
this
.
resultHasMultipleValues
...
...
src/session.ts
View file @
ac786ba0
...
...
@@ -8,8 +8,6 @@ import { Props } from "./props";
import
{
config
}
from
"
./config
"
;
// Calculettes
import
{
YAXB
}
from
"
./axb
"
;
import
{
YAXBParams
}
from
"
./axb_params
"
;
import
{
ConduiteDistrib
}
from
"
./cond_distri
"
;
import
{
LechaptCalmon
}
from
"
./lechaptcalmon
"
;
import
{
MacroRugo
}
from
"
./macrorugo/macrorugo
"
;
...
...
@@ -24,6 +22,8 @@ import { CourbeRemous } from "./remous/remous";
import
{
SectionParametree
}
from
"
./section/section_parametree
"
;
import
{
Solveur
}
from
"
./solveur/solveur
"
;
import
{
SolveurParams
}
from
"
./solveur/solveur_params
"
;
import
{
YAXB
}
from
"
./yaxb
"
;
import
{
YAXBParams
}
from
"
./yaxb_params
"
;
// Classes relatives aux sections
import
{
BiefParams
,
BiefRegime
}
from
"
./remous/bief_params
"
;
...
...
src/axb.ts
→
src/
y
axb.ts
View file @
ac786ba0
import
{
YAXBParams
}
from
"
./axb_params
"
;
import
{
CalculatorType
}
from
"
./compute-node
"
;
import
{
Nub
}
from
"
./nub
"
;
import
{
ParamCalculability
}
from
"
./param/param-definition
"
;
import
{
Message
,
MessageCode
}
from
"
./util/message
"
;
import
{
Result
}
from
"
./util/result
"
;
import
{
YAXBParams
}
from
"
./yaxb_params
"
;
/**
* Y = A.X + B
...
...
src/axb_params.ts
→
src/
y
axb_params.ts
View file @
ac786ba0
File moved
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment