I'm looking at your 'should test switchS()', and the values outputed to "out" array are what I'd expect them to be. I do not see any problem with the test.
Can you explain what you expected to see? Maybe I'm looking in the wrong area.
sss.send(new SS("A", "a", null));
sss.send(new SS("B", "b", null));
sss.send(new SS("C", "c", "sb"));
sss.send(new SS("D", "d", null));
sss.send(new SS("E", "e", "sa"));
sss.send(new SS("F", "f", null));
sss.send(new SS("G", "g", "sb"));
sss.send(new SS("H", "h", "sa"));
sss.send(new SS("I", "i", "sa"));
sss.send(new SS(null, "j", "sb"));
sss.send(new SS("K", null, "sa"));
sss.send(new SS("L", null, "sb"));
sss.send(new SS(null, "m", "sa"));
The third param passed to SS constructor is what it stream will be in use in the NEXT transaction there after (the next send line will witness the new value of the cell value that contains the stream). Where each send
(unless wrapped in Transaction.run()
) is a single transaction. I followed my eyes over it, and what I'd expect it to be matched what was suggested here:
expect(out).toEqual(["A", "B", "C", "d", "e", "F", "G", "h", "I", "L", "m"]);
I should use grammarly, my tone sound angry when I read this. But I'm not angry honest .
This test further down looks a bit funny:
test('should test switchS + Stream.map', (done) => {
const sa = new StreamSink<number>();
const out: number[] = [];
const co = Cell.switchS(new Cell(
new Stream<number>(),
sa.map((a) => {
return sa.map((a_) => a * a_);
}),
));
You've got a Cell constructor taking two parameters, when the Cell constructor (publicly visible one) is meant to take only 1 parameter (the const cell).
If it was intended to use the private constructor for testing. Any lambda expressions containing sodium objects should use the lambda wrappers for the memory management to work.
I.E.
sa.map((a) => {
return sa.map((a_) => a * a_);
}),
becomes
sa.map(lambda1((a) => {
return sa.map((a_) => a * a_);
}, [sa])),
I'm actually a bit confused by the test 'should test switchS + Stream.map' at the moment. I'll look more into it later.