additional test for expected states
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Timo Hocker 2020-10-05 20:15:22 +02:00
parent 9a2c2ce14c
commit af7bd4e00e

View File

@ -96,4 +96,122 @@ describe ('stream', () => {
stream.end_graph ();
stream.end ();
}));
// eslint-disable-next-line max-lines-per-function
it ('should reject invalid command sequences', () => {
/**
* command valid invalid
* [s] cug, cdg eg, cn, csg, ce, at
* cn eg, cn, csg, ce, at cug, cdg
* cug eg, cn, csg, ce, at cug, cdg
* cdg eg, cn, csg, ce, at cug, cdg
* csg eg, cn, csg, ce, at cug, cdg
* eg eg, cn, csg, ce cug, cdg, at
* at eg, cn, csg, ce cug, cdg, at
* ce eg, cn, csg, ce, at cug, cdg
*/
const cn = (g:GraphStream) => {
g.create_node ('foo');
};
const cug = (g:GraphStream) => {
g.create_graph ('foo', 'u');
};
const cdg = (g:GraphStream) => {
g.create_graph ('foo', 'd');
};
const csg = (g:GraphStream) => {
g.create_graph ('foo', 's');
};
const eg = (g:GraphStream) => {
g.end_graph ();
};
const at = (g:GraphStream) => {
g.attributes ({ color: 'red' });
};
const ce = (g:GraphStream) => {
g.create_edge ('foo', 'bar');
};
const combinations = [
{
primary: (g:GraphStream) => {
cug (g);
cn (g);
},
secondary: [
cug,
cdg
]
},
{
primary: cug,
secondary: [
cug,
cdg
]
},
{
primary: cdg,
secondary: [
cug,
cdg
]
},
{
primary: (g:GraphStream) => {
cug (g);
csg (g);
},
secondary: [
cug,
cdg
]
},
{
primary: (g:GraphStream) => {
cug (g);
csg (g);
eg (g);
},
secondary: [
cug,
cdg,
at
]
},
{
primary: (g:GraphStream) => {
cug (g);
at (g);
},
secondary: [
cug,
cdg,
at
]
},
{
primary: (g:GraphStream) => {
cug (g);
ce (g);
},
secondary: [
cug,
cdg
]
}
];
for (const comb of combinations) {
for (const secondary of comb.secondary) {
const g = (new GraphStream);
comb.primary (g);
expect (() => secondary (g))
.toThrowError (
/invalid state to execute command.*?expected:.*?actual:/uis
);
}
}
});
});