public void SmallTest() { var g1 = new BidirectionalGraph <int, Edge <int> >(); var g2 = new BidirectionalGraph <int, Edge <int> >(); g1.AddVerticesAndEdgeRange(new[] { new Edge <int>(1, 2), new Edge <int>(1, 3), new Edge <int>(2, 4) }); g2.AddVerticesAndEdgeRange(new[] { new Edge <int>(1, 2), new Edge <int>(1, 3), new Edge <int>(2, 4) }); var dictionary = new Dictionary <Tuple <int, int>, double>(); foreach (var i in g1.Vertices) { foreach (var j in g2.Vertices) { if (i == j) { dictionary[Tuple.Create(i, j)] = 1.0; } else { dictionary[Tuple.Create(i, j)] = 0.0; } } } var algo = new MaxCardinality <int, Edge <int> >(g1, g2, dictionary, 0.5, (u, v) => new Edge <int>(u, v)); var res = algo.compMaxCardinality(); var e = Enumerable.Range(1, 4).Select(x => Tuple.Create(x, x)); var correctResult = SetModule.OfSeq(e); Assert.AreEqual(res, correctResult); }
public void SerializationTests_FSharp_Collections() { var elements = new List <int>() { 0, 1, 2 }; var mapElements = new List <Tuple <int, string> >() { new Tuple <int, string>(0, "zero"), new Tuple <int, string>(1, "one") }; // F# list RoundtripSerializationTest(ListModule.Empty <int>()); RoundtripSerializationTest(ListModule.OfSeq(elements)); // F# set RoundtripSerializationTest(SetModule.Empty <int>()); RoundtripSerializationTest(SetModule.OfSeq(elements)); // F# map RoundtripSerializationTest(MapModule.OfSeq(new List <Tuple <int, string> >())); RoundtripSerializationTest(MapModule.OfSeq(mapElements)); }
public void Test5_1_Collections() { var m1 = new MegaType( new[] { 0, 1 }, new FSharpMap <string, int>(new List <Tuple <string, int> > { new Tuple <string, int>("key", 10) }), new FSharpSet <int>(new[] { 1 }), new FSharpList <FSharpOption <int> >(new FSharpOption <int>(22), FSharpList <FSharpOption <int> > .Empty), new[] { new[] { 0, 1 } }, new int[, ] { } ); Assert.True(MapModule.ContainsKey("key", m1.Maps)); var newSet = SetModule.Add(2, m1.Sets); //does not mutate set Assert.NotEqual(newSet, m1.Sets); if (OptionModule.IsSome(ListModule.Head(m1.Lists))) { Assert.Equal(22, ListModule.Head(m1.Lists).Value); } //Lists are linked lists, immutable and have structural equality Assert.Equal(m1.Arrays, m1.ArrayofArrays[0]); //Structural equality m1.Arrays[0] = 1; Assert.Equal(m1.Arrays, new[] { 1, 1 }); //Arrays are mutable }
public override FSharpSet <T> Deserialize(ref byte[] bytes, int offset, DirtyTracker tracker, out int byteSize) { // tracker.Dirty(); // immutable var length = BinaryUtil.ReadInt32(ref bytes, offset); if (length == -1) { byteSize = 4; return(null); } ZeroFormatterSerializer.ValidateNewLength(length); var startOffset = offset; offset += 4; int size; var result = new T[length]; for (int i = 0; i < length; i++) { result[i] = formatter.Deserialize(ref bytes, offset, tracker, out size); offset += size; } byteSize = offset - startOffset; return(SetModule.OfArray(result)); }
public override void Setup(BenchmarkContext context) { base.Setup(context); var set = SetModule.OfArray(new[] { 123, 2342355, 456456467578, 234234, -234281 }); InitStreamWith(set); }
public void CanSerializeFSharpSet() { var expected = SetModule.OfArray(new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }); Serialize(expected); Reset(); var actual = Deserialize <object>(); Assert.Equal(expected, actual); }
public override FSharpSet <T> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { try { return(SetModule.OfSeq(reader.DeserializeArray <T>(options))); } catch (Exception ex) { throw new JsonException( $"Error when deserialize FSharpSet<{typeof(T).Name}>", ex); } }
protected override void Init() { base.Init(); list = ListModule.OfArray(new[] { 123, 2342355, 456456467578, 234234, -234281 }); set = SetModule.OfArray(new[] { 123, 2342355, 456456467578, 234234, -234281 }); record = new TestRecord( name: "John Doe", aref: FSharpOption <string> .Some("ok"), connections: "test"); du = DU2.NewC(DU1.NewB("test", 123)); sdu = SDU1.NewB("hello", 123); }
public void DeepCopyTests_FSharp_Collections() { // F# list { var original = FSharpList <int> .Empty; var copy = (FSharpList <int>) this.fixture.SerializationManager.DeepCopy(original); Assert.Equal(original, copy); } { var original = ListModule.OfSeq(new List <int> { 0, 1, 2 }); var copy = (FSharpList <int>) this.fixture.SerializationManager.DeepCopy(original); Assert.Equal(original, copy); } // F# set { var original = new FSharpSet <int>(new List <int>()); var copy = (FSharpSet <int>) this.fixture.SerializationManager.DeepCopy(original); Assert.Equal(original, copy); } { var elements = new List <int>() { 0, 1, 2 }; var original = SetModule.OfSeq(elements); var copy = (FSharpSet <int>) this.fixture.SerializationManager.DeepCopy(original); Assert.Equal(original, copy); } // F# map { var original = new FSharpMap <int, string>(new List <Tuple <int, string> >()); var copy = (FSharpMap <int, string>) this.fixture.SerializationManager.DeepCopy(original); Assert.Equal(original, copy); } { var elements = new List <Tuple <int, string> >() { new Tuple <int, string>(0, "zero"), new Tuple <int, string>(1, "one") }; var original = MapModule.OfSeq(elements); var copy = (FSharpMap <int, string>) this.fixture.SerializationManager.DeepCopy(original); Assert.Equal(original, copy); } }
public void Set() { FSharpSet <int> l = SetModule.OfSeq(new List <int> { 1, 2, 3 }); string json = JsonConvert.SerializeObject(l, Formatting.Indented); Assert.AreEqual(@"[ 1, 2, 3 ]", json); FSharpSet <int> l2 = JsonConvert.DeserializeObject <FSharpSet <int> >(json); Assert.AreEqual(l.Count, l2.Count); CollectionAssert.AreEquivalent(l, l2); }
public void DifferentGraphsTest() { var g1 = new BidirectionalGraph <int, Edge <int> >(); var g2 = new BidirectionalGraph <int, Edge <int> >(); g1.AddVerticesAndEdgeRange(new[] { new Edge <int>(1, 2), new Edge <int>(1, 3), new Edge <int>(2, 4), new Edge <int>(2, 5) }); g2.AddVerticesAndEdgeRange(new[] { new Edge <int>(1, 2), new Edge <int>(2, 3), new Edge <int>(2, 4) }); var dictionary = new Dictionary <Tuple <int, int>, double>(); foreach (var i in g1.Vertices) { foreach (var j in g2.Vertices) { dictionary[Tuple.Create(i, j)] = 0.0; } } dictionary[Tuple.Create(1, 1)] = 1.0; dictionary[Tuple.Create(2, 2)] = 1.0; dictionary[Tuple.Create(3, 2)] = 0.6; dictionary[Tuple.Create(4, 3)] = 1.0; dictionary[Tuple.Create(5, 4)] = 1.0; var algo = new MaxCardinality <int, Edge <int> >(g1, g2, dictionary, 0.5, (u, v) => new Edge <int>(u, v)); var res = algo.compMaxCardinality(); var correctResult = SetModule.Empty <Tuple <int, int> >() .Add(Tuple.Create(1, 1)) .Add(Tuple.Create(2, 2)) .Add(Tuple.Create(3, 2)) .Add(Tuple.Create(4, 3)) .Add(Tuple.Create(5, 4)); Assert.AreEqual(res, correctResult); }
public async Task <bool> Collect(Tuple <Guid, int> exampleRevisionId, FSharpOption <Guid> deckId) // highTODO this needs serious fixing { var meta = await _metaFactory.Create(); var exampleState = await _dexie.GetExampleState(exampleRevisionId.Item1); var exampleRevision = Domain.Example.getRevision(exampleRevisionId.Item1, exampleRevisionId.Item2, exampleState).ResultValue; var templateState = await _dexie.GetTemplateState(exampleRevision.TemplateRevisionId.Item1); var templateRevision = toTemplateRevision(await _dexie.GetTemplateInstance(exampleRevision.TemplateRevisionId)); var pointers = PublicTemplate.getCardTemplatePointers(templateRevision, exampleRevision.FieldValues).ResultValue; var user = await _userProvider.ForceSummary(); var cardSetting = user.CardSettings.Single(x => x.IsDefault); var deckIds = deckId.IsSome() ? SetModule.Singleton(deckId.Value) : (await _dexie.GetViewDecks()).Where(x => x.IsDefault).Select(x => x.Id).Pipe(SetModule.OfSeq); var cards = pointers.Select(p => Stack.initCard(_clock.GetCurrentInstant(), cardSetting.Id, cardSetting.NewCardsStartingEaseFactor, p)).ToFList(); var stackId = Guid.NewGuid(); var created = Stack.init(stackId, meta, exampleRevision.TemplateRevisionId.Item1, exampleRevision.TemplateRevisionId.Item2, deckIds, exampleRevision.Title, exampleRevision.FieldValues, cards); var stackState = await _dexie.GetStackState(stackId); return(await _transact(stackId, Stack.decideCreate(created, templateState, stackState))); }
protected override FSharpSet <T> Complete(T[] intermediateCollection) { return(SetModule.OfArray(intermediateCollection)); }
public void Simple() => Helper.MakeSimpleTest(SetModule.OfArray(new[] { 1, 2, 3 }), Options);
public void InObject() => Helper.MakeObjectTest(SetModule.OfArray(new[] { 1, 2, 3 }), Options);
public static Set1 <T> Build(T first, IEnumerable <T> rest) => new Set1 <T>(SetModule.OfSeq(new[] { first }.Concat(rest))); // important - first in first, or we may change semantics if 'rest' includes 'first' value
public void Serialize_FSharpSet() { var set = SetModule.OfArray(new[] { 123, 2342355, 456456467578, 234234, -234281 }); SerializeAndCount(set); }
public WorldModel Put(FSharpSet <EntityModel> entities, EntityModel on) { return(new WorldModel(Entity, Task, Plan, Holding.Add(on, SetModule.Union(Holding[on], entities)), Doing, BelongsTo)); }