public void FrequencyTest3() { var input = new int[] { 1, 2, 3, 4, 3, 2, 3, 3, 3, 3, 2, 2, 2, 3, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 3, 2, 2, 3, 3, 2, 2, 2, 2, 2, 2, 3, 3, 1, 1, 2, 2, 1, 2, 1, 1, 2, 1, 2 }; var buckets = new string[] { "a", "b", "c", "Z1", "Z2" }; Func <int, IEnumerable <string>, string> bucketSelector = BucketSelector; var expected = new KeyValuePair <string, int>[] { new KeyValuePair <string, int>("a", 13), new KeyValuePair <string, int>("b", 23), new KeyValuePair <string, int>("c", 12), new KeyValuePair <string, int>("Z1", 1), new KeyValuePair <string, int>("Z2", 0) }; var actual = MathTool.Frequency(input, buckets, bucketSelector); if (IsDebugEnabled) { log.Debug(@"expected=[{0}], actual=[{1}]", expected.CollectionToString(), actual.CollectionToString()); } Assert.IsTrue(expected.SequenceEqual(actual)); }
public static Expression RestoreSnapshot(KeyValuePair<string, List<Type>>[] SnapshotData) { if (SnapshotData.SequenceEqual(CurrentScope.OnDateType)) return null; var Ret = Expression.Block( SnapshotData.Except(CurrentScope.OnDateType) .SelectMany(x => x.Value.Select(y => CurrentScope.GetVarCached(x.Key, y))) ); SnapshotData = null; return Ret; }
public void 拷貝SafeDictionary_從Index0開始拷貝_拷貝的結果應該與SafeDictionary相同() { var safeDictionary = new SafeDictionary <int, int>(); var fixture = new Fixture(); safeDictionary.AddMany(fixture.Create <KeyValuePair <int, int> >, 3); var array = new KeyValuePair <int, int> [3]; safeDictionary.CopyTo(array, 0); array.SequenceEqual(safeDictionary).Should().Be(true); }
public void FrequencyTest1() { IEnumerable <int> input = new int[] { 1, 2, 3, 4, 3, 2, 3, 3, 3, 3, 2, 2, 2, 3, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 3, 2, 2, 3, 3, 2, 2, 2, 2, 2, 2, 3, 3, 1, 1, 2, 2, 1, 2, 1, 1, 2, 1, 2 }; IEnumerable <KeyValuePair <int, int> > expected = new KeyValuePair <int, int>[] { new KeyValuePair <int, int>(1, 13), new KeyValuePair <int, int>(2, 23), new KeyValuePair <int, int>(3, 12), new KeyValuePair <int, int>(4, 1) }; IEnumerable <KeyValuePair <int, int> > actual; actual = input.Frequency(); Assert.IsTrue(expected.SequenceEqual(actual)); }
public void FrequencyTest3() { IEnumerable <int> input = new int[] { 1, 2, 3, 4, 3, 2, 3, 3, 3, 3, 2, 2, 2, 3, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 3, 2, 2, 3, 3, 2, 2, 2, 2, 2, 2, 3, 3, 1, 1, 2, 2, 1, 2, 1, 1, 2, 1, 2 }; IEnumerable <string> buckets = new string[] { "a", "b", "c", "Z1", "Z2" }; Func <int, IEnumerable <string>, string> bucketSelector = BucketSelector; IEnumerable <KeyValuePair <string, int> > expected = new KeyValuePair <string, int>[] { new KeyValuePair <string, int>("a", 13), new KeyValuePair <string, int>("b", 23), new KeyValuePair <string, int>("c", 12), new KeyValuePair <string, int>("Z1", 1), new KeyValuePair <string, int>("Z2", 0) }; IEnumerable <KeyValuePair <string, int> > actual; actual = Statistical.Frequency(input, buckets, bucketSelector); Assert.IsTrue(expected.SequenceEqual(actual)); }
public void FrequencyTest2() { IEnumerable <int> input = new int[] { 1, 2, 3, 4, 3, 2, 3, 3, 3, 3, 2, 2, 2, 3, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 3, 2, 2, 3, 3, 2, 2, 2, 2, 2, 2, 3, 3, 1, 1, 2, 2, 1, 2, 1, 1, 2, 1, 2 }; Func <int, string> bucketSelector = delegate(int X) { if (X <= 2) { return("2 and under"); } else { return("Over 2"); } }; IEnumerable <KeyValuePair <string, int> > expected = new KeyValuePair <string, int>[] { new KeyValuePair <string, int>("2 and under", 36), new KeyValuePair <string, int>("Over 2", 13) }; IEnumerable <KeyValuePair <string, int> > actual; actual = input.Frequency(bucketSelector); Assert.IsTrue(expected.SequenceEqual(actual)); }
public void FrequencyTest2() { var input = new int[] { 1, 2, 3, 4, 3, 2, 3, 3, 3, 3, 2, 2, 2, 3, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 3, 2, 2, 3, 3, 2, 2, 2, 2, 2, 2, 3, 3, 1, 1, 2, 2, 1, 2, 1, 1, 2, 1, 2 }; Func<int, string> bucketSelector = X => X <= 2 ? "2 and under" : "Over 2"; var expected = new KeyValuePair<string, int>[] { new KeyValuePair<string, int>("2 and under", 36), new KeyValuePair<string, int>("Over 2", 13) }; var actual = input.Frequency(bucketSelector); if(IsDebugEnabled) log.Debug(@"expected=[{0}], actual=[{1}]", expected.CollectionToString(), actual.CollectionToString()); Assert.IsTrue(expected.SequenceEqual(actual)); }
public void TestCopyTo_Explicit() { var dictionary = new Dictionary <int, int>() { { 0, 0 }, { 1, 1 }, { 2, 2 } }.Defaulted(); ICollection <KeyValuePair <int, int> > collection = dictionary; KeyValuePair <int, int>[] array = new KeyValuePair <int, int> [dictionary.Count]; int arrayIndex = 0; collection.CopyTo(array, arrayIndex); KeyValuePair <int, int>[] expected = new KeyValuePair <int, int> [dictionary.Count]; dictionary.Dictionary.CopyTo(expected, 0); Assert.IsTrue(array.SequenceEqual(expected), "The values were not copied as expected."); }
public void HashTableCopyTo() { var values = new List <KeyValuePair <string, int> >() { new KeyValuePair <string, int>("one", 1), new KeyValuePair <string, int>("two", 2), new KeyValuePair <string, int>("three", 3), }; var table = new HashTable <string, int>(); foreach (var value in values) { table.Add(value); } var array = new KeyValuePair <string, int> [3]; table.CopyTo(array, 0); Assert.IsTrue(array.SequenceEqual(values)); }
public void FrequencyTest1() { var input = new int[] { 1, 2, 3, 4, 3, 2, 3, 3, 3, 3, 2, 2, 2, 3, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 3, 2, 2, 3, 3, 2, 2, 2, 2, 2, 2, 3, 3, 1, 1, 2, 2, 1, 2, 1, 1, 2, 1, 2 }; var expected = new KeyValuePair<int, int>[] { new KeyValuePair<int, int>(1, 13), new KeyValuePair<int, int>(2, 23), new KeyValuePair<int, int>(3, 12), new KeyValuePair<int, int>(4, 1) }; var actual = input.Frequency(); if(IsDebugEnabled) log.Debug(@"expected=[{0}], actual=[{1}]", expected.CollectionToString(), actual.CollectionToString()); Assert.IsTrue(expected.SequenceEqual(actual)); }
public void FrequencyTest2() { var input = new int[] { 1, 2, 3, 4, 3, 2, 3, 3, 3, 3, 2, 2, 2, 3, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 3, 2, 2, 3, 3, 2, 2, 2, 2, 2, 2, 3, 3, 1, 1, 2, 2, 1, 2, 1, 1, 2, 1, 2 }; Func <int, string> bucketSelector = X => X <= 2 ? "2 and under" : "Over 2"; var expected = new KeyValuePair <string, int>[] { new KeyValuePair <string, int>("2 and under", 36), new KeyValuePair <string, int>("Over 2", 13) }; var actual = input.Frequency(bucketSelector); if (IsDebugEnabled) { log.Debug(@"expected=[{0}], actual=[{1}]", expected.CollectionToString(), actual.CollectionToString()); } Assert.IsTrue(expected.SequenceEqual(actual)); }
public void FrequencyTest3() { var input = new int[] { 1, 2, 3, 4, 3, 2, 3, 3, 3, 3, 2, 2, 2, 3, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 3, 2, 2, 3, 3, 2, 2, 2, 2, 2, 2, 3, 3, 1, 1, 2, 2, 1, 2, 1, 1, 2, 1, 2 }; var buckets = new string[] { "a", "b", "c", "Z1", "Z2" }; Func<int, IEnumerable<string>, string> bucketSelector = BucketSelector; var expected = new KeyValuePair<string, int>[] { new KeyValuePair<string, int>("a", 13), new KeyValuePair<string, int>("b", 23), new KeyValuePair<string, int>("c", 12), new KeyValuePair<string, int>("Z1", 1), new KeyValuePair<string, int>("Z2", 0) }; var actual = MathTool.Frequency(input, buckets, bucketSelector); if(IsDebugEnabled) log.Debug(@"expected=[{0}], actual=[{1}]", expected.CollectionToString(), actual.CollectionToString()); Assert.IsTrue(expected.SequenceEqual(actual)); }
public void FrequencyTest1() { var input = new int[] { 1, 2, 3, 4, 3, 2, 3, 3, 3, 3, 2, 2, 2, 3, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 3, 2, 2, 3, 3, 2, 2, 2, 2, 2, 2, 3, 3, 1, 1, 2, 2, 1, 2, 1, 1, 2, 1, 2 }; var expected = new KeyValuePair <int, int>[] { new KeyValuePair <int, int>(1, 13), new KeyValuePair <int, int>(2, 23), new KeyValuePair <int, int>(3, 12), new KeyValuePair <int, int>(4, 1) }; var actual = input.Frequency(); if (IsDebugEnabled) { log.Debug(@"expected=[{0}], actual=[{1}]", expected.CollectionToString(), actual.CollectionToString()); } Assert.IsTrue(expected.SequenceEqual(actual)); }
public void CopyTo() { IDictionary<string, string> dict = new Dictionary<string, string>(); dict.Add("Key", "Value"); dict.Add("OtherKey", "OtherValue"); dict = dict.ToReadOnlyDictionary(); var values = new KeyValuePair<string, string>[3]; var expectedValues = new[] { KeyValuePair.Create("Key", "Value"), KeyValuePair.Create("OtherKey", "OtherValue"), default(KeyValuePair<string, string>) }; dict.CopyTo(values, 0); Assert.IsTrue(values.SequenceEqual(expectedValues)); dict.CopyTo(values, 1); expectedValues[2] = expectedValues[1]; expectedValues[1] = expectedValues[0]; Assert.IsTrue(values.SequenceEqual(expectedValues)); }