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 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); } }
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 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