public void TestSwitchC() { StreamSink <Sc> ssc = Stream.CreateSink <Sc>(); // Split each field out of SB so we can update multiple behaviors in a // single transaction. DiscreteCell <char> ca = ssc.Map(s => s.A).FilterMaybe().Hold('A'); DiscreteCell <char> cb = ssc.Map(s => s.B).FilterMaybe().Hold('a'); DiscreteCell <DiscreteCell <char> > csw = ssc.Map(s => s.Sw).FilterMaybe().Hold(ca); DiscreteCell <char> co = csw.SwitchC(); List <char> @out = new List <char>(); IListener l = co.Listen(@out.Add); ssc.Send(new Sc(Maybe.Just('B'), Maybe.Just('b'), Maybe.Nothing <DiscreteCell <char> >())); ssc.Send(new Sc(Maybe.Just('C'), Maybe.Just('c'), Maybe.Just(cb))); ssc.Send(new Sc(Maybe.Just('D'), Maybe.Just('d'), Maybe.Nothing <DiscreteCell <char> >())); ssc.Send(new Sc(Maybe.Just('E'), Maybe.Just('e'), Maybe.Just(ca))); ssc.Send(new Sc(Maybe.Just('F'), Maybe.Just('f'), Maybe.Nothing <DiscreteCell <char> >())); ssc.Send(new Sc(Maybe.Nothing <char>(), Maybe.Nothing <char>(), Maybe.Just(cb))); ssc.Send(new Sc(Maybe.Nothing <char>(), Maybe.Nothing <char>(), Maybe.Just(ca))); ssc.Send(new Sc(Maybe.Just('G'), Maybe.Just('g'), Maybe.Just(cb))); ssc.Send(new Sc(Maybe.Just('H'), Maybe.Just('h'), Maybe.Just(ca))); ssc.Send(new Sc(Maybe.Just('I'), Maybe.Just('i'), Maybe.Just(ca))); l.Unlisten(); CollectionAssert.AreEqual(new[] { 'A', 'B', 'c', 'd', 'E', 'F', 'f', 'F', 'g', 'H', 'I' }, @out); }
public void Test_SwitchC_TestCase3() { RunPermutations <char>(createFiringsListAndListener => { Tuple <Stream <char>, Dictionary <int, Action> > s1T = MkStream(new Dictionary <int, char> { { 0, 'b' }, { 1, 'c' }, { 2, 'd' }, { 3, 'e' } }); Stream <char> s1 = s1T.Item1; Dictionary <int, Action> s1F = s1T.Item2; DiscreteCell <char> c1 = s1.Hold('a'); Tuple <Stream <char>, Dictionary <int, Action> > s2T = MkStream(new Dictionary <int, char> { { 2, 'Y' }, { 3, 'Z' } }); Stream <char> s2 = s2T.Item1; Dictionary <int, Action> s2F = s2T.Item2; DiscreteCell <char> c2 = s2.Hold('X'); Tuple <Stream <DiscreteCell <char> >, Dictionary <int, Action> > switcherT = MkStream(new Dictionary <int, DiscreteCell <char> > { { 1, c2 } }); Stream <DiscreteCell <char> > switcher = switcherT.Item1; Dictionary <int, Action> switcherF = switcherT.Item2; DiscreteCell <DiscreteCell <char> > c = switcher.Hold(c1); IReadOnlyList <Tuple <string, Dictionary <int, Action> > > firings = new[] { Tuple.Create("s1", s1F), Tuple.Create("s2", s2F), Tuple.Create("switcher", switcherF) }; return(createFiringsListAndListener(firings, c.SwitchC().Listen)); }, @out => CollectionAssert.AreEqual(new[] { 'b', 'X', 'Y', 'Z' }, @out)); }
public static Stream <T> SwitchCWithDeferredValues <T>(this DiscreteCell <DiscreteCell <T> > cca) { return(Operational.Defer(cca.SwitchC().Values)); }