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
89d34483
Commit
89d34483
authored
Nov 13, 2019
by
Mathias Chouet
🍝
Browse files
YAXN: restrict N to integers, add specs
parent
a9bf6490
Changes
4
Hide whitespace changes
Inline
Side-by-side
spec/yaxn.spec.ts
0 → 100644
View file @
89d34483
import
{
YAXN
}
from
"
../src/yaxn
"
;
import
{
YAXNParams
}
from
"
../src/yaxn_params
"
;
describe
(
"
Class YAXN:
"
,
()
=>
{
it
(
"
Y should be 65.625
"
,
()
=>
{
const
nub
=
new
YAXN
(
new
YAXNParams
(
4.2
,
2.5
,
3
));
nub
.
calculatedParam
=
nub
.
prms
.
Y
;
nub
.
CalcSerie
();
expect
(
nub
.
result
.
vCalc
).
toBe
(
65.625
);
});
it
(
"
X should be 2.5
"
,
()
=>
{
const
nub
=
new
YAXN
(
new
YAXNParams
(
4.2
,
666
,
3
,
65.625
));
nub
.
calculatedParam
=
nub
.
prms
.
X
;
nub
.
CalcSerie
();
expect
(
nub
.
result
.
vCalc
).
toBe
(
2.5
);
});
it
(
"
non-integer N should trigger error
"
,
()
=>
{
expect
(()
=>
{
const
nub
=
new
YAXN
(
new
YAXNParams
(
10
,
4
,
3.2
));
nub
.
calculatedParam
=
nub
.
prms
.
Y
;
nub
.
CalcSerie
();
}).
toThrow
();
});
});
src/param/param-definition.ts
View file @
89d34483
...
...
@@ -569,6 +569,15 @@ export class ParamDefinition implements INamedIterableValues, IObservable {
}
break
;
case
ParamDomainValue
.
INTEGER
:
if
(
!
Number
.
isInteger
(
v
))
{
const
f
=
new
Message
(
MessageCode
.
ERROR_PARAMDEF_VALUE_INTEGER
);
f
.
extraVar
.
symbol
=
this
.
symbol
;
f
.
extraVar
.
value
=
v
;
throw
f
;
}
break
;
default
:
const
e
=
new
Message
(
MessageCode
.
ERROR_PARAMDOMAIN_INVALID
);
e
.
extraVar
.
symbol
=
this
.
symbol
;
...
...
src/param/param-domain.ts
View file @
89d34483
...
...
@@ -5,30 +5,23 @@ import { Message, MessageCode } from "../util/message";
* domaine de définition du paramètre
*/
export
enum
ParamDomainValue
{
/**
* >0, =0, <0 (-inf -> +inf)
*/
/** >0, =0, <0 (-inf -> +inf) */
ANY
,
/**
* >=0
*/
/** >=0 */
POS_NULL
,
/**
* > 0
*/
/** > 0 */
POS
,
/**
* <>0
*/
/** <>0 */
NOT_NULL
,
/**
* intervalle
*/
INTERVAL
/** intervalle */
INTERVAL
,
/** nombre entier relatif */
INTEGER
}
export
class
ParamDomain
{
...
...
@@ -41,6 +34,7 @@ export class ParamDomain {
case
ParamDomainValue
.
ANY
:
case
ParamDomainValue
.
NOT_NULL
:
case
ParamDomainValue
.
INTEGER
:
return
{
min
:
-
Infinity
,
max
:
Infinity
};
case
ParamDomainValue
.
POS
:
...
...
src/yaxn_params.ts
View file @
89d34483
...
...
@@ -19,17 +19,17 @@ export class YAXNParams extends ParamsEquation {
/** N */
private
_N
:
ParamDefinition
;
constructor
(
rA
:
number
,
rX
:
number
,
rN
:
number
)
{
constructor
(
rA
:
number
,
rX
:
number
,
rN
:
number
,
rY
?:
number
)
{
super
();
this
.
_Y
=
new
ParamDefinition
(
this
,
"
Y
"
,
ParamDomainValue
.
ANY
,
undefined
,
undefined
,
undefined
,
false
);
this
.
_A
=
new
ParamDefinition
(
this
,
"
A
"
,
ParamDomainValue
.
ANY
,
undefined
,
rA
);
this
.
_X
=
new
ParamDefinition
(
this
,
"
X
"
,
ParamDomainValue
.
ANY
,
undefined
,
rX
,
ParamFamily
.
ANY
);
this
.
_N
=
new
ParamDefinition
(
this
,
"
N
"
,
ParamDomainValue
.
ANY
,
undefined
,
rN
);
this
.
_N
=
new
ParamDefinition
(
this
,
"
N
"
,
ParamDomainValue
.
INTEGER
,
undefined
,
rN
);
this
.
_Y
=
new
ParamDefinition
(
this
,
"
Y
"
,
ParamDomainValue
.
ANY
,
undefined
,
rY
,
undefined
,
false
);
this
.
addParamDefinition
(
this
.
_Y
);
this
.
addParamDefinition
(
this
.
_A
);
this
.
addParamDefinition
(
this
.
_X
);
this
.
addParamDefinition
(
this
.
_N
);
this
.
addParamDefinition
(
this
.
_Y
);
}
get
Y
()
{
...
...
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