public void GetValueReturnsValueOnlyIfTheBindingIndexIsZero(string path, object index) { ScalarDataItem<object> item = new ScalarDataItem<object>(42, null, false); object value = item.GetValue(new DataBinding((int?)index, path)); Assert.AreEqual(42, value); }
public void GetValueReturnsValueOnlyIfTheBindingIndexIsZero(string path, object index) { ScalarDataItem <object> item = new ScalarDataItem <object>(42, null, false); object value = item.GetValue(new DataBinding((int?)index, path)); Assert.AreEqual(42, value); }
public void HasNoMetadataIfNullSpecifiedInConstructor() { ScalarDataItem <object> item = new ScalarDataItem <object>(null, null, false); PropertyBag metadata = DataItemUtils.GetMetadata(item); Assert.Count(0, metadata); }
public void CanGetDescriptiveDataBindingsFromItem() { ScalarDataItem<string> item = new ScalarDataItem<string>("abc", null, false); Assert.AreElementsEqual(new[] { new DataBinding(0, null) }, item.GetBindingsForInformalDescription()); }
public void CanGetDescriptiveDataBindingsFromItem() { ScalarDataItem <string> item = new ScalarDataItem <string>("abc", null, false); Assert.AreElementsEqual(new[] { new DataBinding(0, null) }, item.GetBindingsForInformalDescription()); }
public void ContainSameMetadataAsSpecifiedInConstructor() { List<KeyValuePair<string, string>> metadataPairs = new List<KeyValuePair<string, string>>(); metadataPairs.Add(new KeyValuePair<string, string>("Foo", "Bar")); ScalarDataItem<object> item = new ScalarDataItem<object>("abc", metadataPairs, false); PropertyBag map = DataItemUtils.GetMetadata(item); Assert.Count(1, map); Assert.AreEqual("Bar", map.GetValue("Foo")); }
public void ContainSameMetadataAsSpecifiedInConstructor() { List <KeyValuePair <string, string> > metadataPairs = new List <KeyValuePair <string, string> >(); metadataPairs.Add(new KeyValuePair <string, string>("Foo", "Bar")); ScalarDataItem <object> item = new ScalarDataItem <object>("abc", metadataPairs, false); PropertyBag map = DataItemUtils.GetMetadata(item); Assert.Count(1, map); Assert.AreEqual("Bar", map.GetValue("Foo")); }
public void JoinProducesCoveringsOfAllPairs(int[] counts, int empiricalUpperBound) { int dimensions = counts.Length; DataBinding binding = new DataBinding(0, null); IDataProvider[] providers = new IDataProvider[dimensions]; DataBinding[][] bindingsPerProvider = new DataBinding[dimensions][]; for (int i = 0; i < dimensions; i++) { providers[i] = Mocks.StrictMock<IDataProvider>(); bindingsPerProvider[i] = new DataBinding[] { binding }; IDataItem[] providerItems = new IDataItem[counts[i]]; for (int j = 0; j < counts[i]; j++) providerItems[j] = new ScalarDataItem<int>(j, null, false); Expect.Call(providers[i].GetItems(bindingsPerProvider[i], true)).Return(providerItems); } Mocks.ReplayAll(); List<IList<IDataItem>> itemLists = new List<IList<IDataItem>>(PairwiseJoinStrategy.Instance.Join(providers, bindingsPerProvider, true)); int[][] values = new int[itemLists.Count][]; using (TestLog.BeginSection(String.Format("{0} combinations.", itemLists.Count))) { for (int i = 0; i < itemLists.Count; i++) { IList<IDataItem> itemList = itemLists[i]; Assert.AreEqual(dimensions, itemList.Count); values[i] = new int[dimensions]; for (int j = 0; j < itemList.Count; j++) { int value = (int)itemList[j].GetValue(binding); values[i][j] = value; if (j != 0) TestLog.Write(","); TestLog.Write(value); } TestLog.WriteLine(); } } // Check pairings. bool missingPairing = false; double meanOccurrences = 0; double stdevOccurrences = 0; int pairingCount = 0; using (TestLog.BeginSection("Pairings")) { for (int firstDimension = 0; firstDimension < dimensions; firstDimension++) { for (int secondDimension = firstDimension + 1; secondDimension < dimensions; secondDimension++) { for (int firstValue = 0; firstValue < counts[firstDimension]; firstValue++) { for (int secondValue = 0; secondValue < counts[secondDimension]; secondValue++) { int occurrences = 0; for (int i = 0; i < values.Length; i++) if (values[i][firstDimension] == firstValue && values[i][secondDimension] == secondValue) occurrences += 1; TestLog.WriteLine("{0} x {1} : ({2}, {3}) -> {4} occurrences.", firstDimension, secondDimension, firstValue, secondValue, occurrences); if (occurrences == 0) missingPairing = true; pairingCount += 1; double diff = occurrences - meanOccurrences; meanOccurrences += diff / pairingCount; stdevOccurrences += diff * (occurrences - meanOccurrences); } } } } } if (pairingCount > 1) stdevOccurrences = Math.Sqrt(stdevOccurrences / (pairingCount - 1)); else stdevOccurrences = 0; using (TestLog.BeginSection("Statistics")) { // A mean of exactly 1 implies we have found a minimal covering. // A low standard deviation indicates good uniformity among the covered pairs. 0 would be ideal. TestLog.WriteLine("Pairing Occurrence Mean: {0}", meanOccurrences); TestLog.WriteLine("Pairing Occurrence Stdev: {0}", stdevOccurrences); } Assert.IsFalse(missingPairing, "One or more pairings were not covered!"); Assert.LessThanOrEqualTo(values.Length, empiricalUpperBound, "There were more combinations produced than previously measured. Has the algorithm gotten worse?"); }
public void HasNoMetadataIfNullSpecifiedInConstructor() { ScalarDataItem<object> item = new ScalarDataItem<object>(null, null, false); PropertyBag metadata = DataItemUtils.GetMetadata(item); Assert.Count(0, metadata); }
public void IsDynamicReturnsSameValueAsWasSpecifiedInTheConstructor(bool isDynamic) { ScalarDataItem<object> item = new ScalarDataItem<object>(null, null, isDynamic); Assert.AreEqual(isDynamic, item.IsDynamic); }
public void JoinProducesCoveringsOfAllPairs(int[] counts, int empiricalUpperBound) { int dimensions = counts.Length; DataBinding binding = new DataBinding(0, null); IDataProvider[] providers = new IDataProvider[dimensions]; DataBinding[][] bindingsPerProvider = new DataBinding[dimensions][]; for (int i = 0; i < dimensions; i++) { providers[i] = Mocks.StrictMock <IDataProvider>(); bindingsPerProvider[i] = new DataBinding[] { binding }; IDataItem[] providerItems = new IDataItem[counts[i]]; for (int j = 0; j < counts[i]; j++) { providerItems[j] = new ScalarDataItem <int>(j, null, false); } Expect.Call(providers[i].GetItems(bindingsPerProvider[i], true)).Return(providerItems); } Mocks.ReplayAll(); List <IList <IDataItem> > itemLists = new List <IList <IDataItem> >(PairwiseJoinStrategy.Instance.Join(providers, bindingsPerProvider, true)); int[][] values = new int[itemLists.Count][]; using (TestLog.BeginSection(String.Format("{0} combinations.", itemLists.Count))) { for (int i = 0; i < itemLists.Count; i++) { IList <IDataItem> itemList = itemLists[i]; Assert.AreEqual(dimensions, itemList.Count); values[i] = new int[dimensions]; for (int j = 0; j < itemList.Count; j++) { int value = (int)itemList[j].GetValue(binding); values[i][j] = value; if (j != 0) { TestLog.Write(","); } TestLog.Write(value); } TestLog.WriteLine(); } } // Check pairings. bool missingPairing = false; double meanOccurrences = 0; double stdevOccurrences = 0; int pairingCount = 0; using (TestLog.BeginSection("Pairings")) { for (int firstDimension = 0; firstDimension < dimensions; firstDimension++) { for (int secondDimension = firstDimension + 1; secondDimension < dimensions; secondDimension++) { for (int firstValue = 0; firstValue < counts[firstDimension]; firstValue++) { for (int secondValue = 0; secondValue < counts[secondDimension]; secondValue++) { int occurrences = 0; for (int i = 0; i < values.Length; i++) { if (values[i][firstDimension] == firstValue && values[i][secondDimension] == secondValue) { occurrences += 1; } } TestLog.WriteLine("{0} x {1} : ({2}, {3}) -> {4} occurrences.", firstDimension, secondDimension, firstValue, secondValue, occurrences); if (occurrences == 0) { missingPairing = true; } pairingCount += 1; double diff = occurrences - meanOccurrences; meanOccurrences += diff / pairingCount; stdevOccurrences += diff * (occurrences - meanOccurrences); } } } } } if (pairingCount > 1) { stdevOccurrences = Math.Sqrt(stdevOccurrences / (pairingCount - 1)); } else { stdevOccurrences = 0; } using (TestLog.BeginSection("Statistics")) { // A mean of exactly 1 implies we have found a minimal covering. // A low standard deviation indicates good uniformity among the covered pairs. 0 would be ideal. TestLog.WriteLine("Pairing Occurrence Mean: {0}", meanOccurrences); TestLog.WriteLine("Pairing Occurrence Stdev: {0}", stdevOccurrences); } Assert.IsFalse(missingPairing, "One or more pairings were not covered!"); Assert.LessThanOrEqualTo(values.Length, empiricalUpperBound, "There were more combinations produced than previously measured. Has the algorithm gotten worse?"); }
public void IsDynamicReturnsSameValueAsWasSpecifiedInTheConstructor(bool isDynamic) { ScalarDataItem <object> item = new ScalarDataItem <object>(null, null, isDynamic); Assert.AreEqual(isDynamic, item.IsDynamic); }