private static DenseMap <int, HashSet <int> > ParseDenseMap(string text) { text = text.Trim(); // Empty string means empty set if (text.Length == 0) { return(new()); } // Split by Union and parse intervals var intervalParts = text.Split('U'); var intervalSetPairs = intervalParts.Select(ParseAssociation); // Construct the dense set var result = new DenseMap <int, HashSet <int> >(HashSetCombiner); foreach (var(iv, set) in intervalSetPairs) { result.Add(iv, set); } // Check equality AssertEquals(result, intervalSetPairs); return(result); }
private static void AssertEquals(DenseMap <int, HashSet <int> > a, IEnumerable <KeyValuePair <Interval <int>, HashSet <int> > > b) { // Key equality Assert.True(a.Select(i => i.Key).SequenceEqual(b.Select(i => i.Key))); // Value equality Assert.True(a.Select(i => i.Value).Zip(b.Select(i => i.Value)).All(pair => pair.First.SetEquals(pair.Second))); }