public void SortedArrayListSimpleTest() { var a = new CKSortedArrayList <int>(); a.AddRangeArray(12, -34, 7, 545, 12); a.AllowDuplicates.Should().BeFalse(); a.Count.Should().Be(4); a.Should().BeInAscendingOrder(); a.Contains(14).Should().BeFalse(); a.IndexOf(12).Should().Be(2); object o = 21; a.Contains(o).Should().BeFalse(); a.IndexOf(o).Should().BeLessThan(0); o = 12; a.Contains(o).Should().BeTrue(); a.IndexOf(o).Should().Be(2); o = null; a.Contains(o).Should().BeFalse(); a.IndexOf(o).Should().Be(int.MinValue); int[] arrayToTest = new int[5]; a.CopyTo(arrayToTest, 1); arrayToTest[0].Should().Be(0); arrayToTest[1].Should().Be(-34); arrayToTest[4].Should().Be(545); }
public void testing_capacity_changes() { var a = new CKSortedArrayList <Mammal>((a1, a2) => a1.Name.CompareTo(a2.Name)); a.Capacity.Should().Be(0); a.Capacity = 3; a.Capacity.Should().Be(4); a.Capacity = 0; a.Capacity.Should().Be(0); a.Add(new Mammal("1")); a.Invoking(sut => sut.Capacity = 0).Should().Throw <ArgumentException>(); a.Add(new Mammal("2")); a.Add(new Mammal("3")); a.Add(new Mammal("4")); a.Add(new Mammal("5")); a.Capacity.Should().Be(8); a.Capacity = 5; a.Capacity.Should().Be(5); a.Add(new Mammal("6")); a.Add(new Mammal("7")); a.Add(new Mammal("8")); a.Add(new Mammal("9")); a.Add(new Mammal("10")); a.Capacity.Should().Be(10); a.Clear(); a.Capacity.Should().Be(10); }
public void SortedArrayListSimpleTest() { var a = new CKSortedArrayList <int>(); a.AddRangeArray(12, -34, 7, 545, 12); Assert.That(a.AllowDuplicates, Is.False); Assert.That(a.Count, Is.EqualTo(4)); Assert.That(a, Is.Ordered); Assert.That(a.Contains(14), Is.False); Assert.That(a.IndexOf(12), Is.EqualTo(2)); object o = 21; Assert.That(a.Contains(o), Is.False); Assert.That(a.IndexOf(o), Is.LessThan(0)); o = 12; Assert.That(a.Contains(o), Is.True); Assert.That(a.IndexOf(o), Is.EqualTo(2)); o = null; Assert.That(a.Contains(o), Is.False); Assert.That(a.IndexOf(o), Is.EqualTo(Int32.MinValue)); int[] arrayToTest = new int[5]; a.CopyTo(arrayToTest, 1); Assert.That(arrayToTest[0], Is.EqualTo(0)); Assert.That(arrayToTest[1], Is.EqualTo(-34)); Assert.That(arrayToTest[4], Is.EqualTo(545)); }
public void testing_capacity_changes() { var a = new CKSortedArrayList <Mammal>((a1, a2) => a1.Name.CompareTo(a2.Name)); Assert.That(a.Capacity, Is.EqualTo(0)); a.Capacity = 3; Assert.That(a.Capacity, Is.EqualTo(4)); a.Capacity = 0; Assert.That(a.Capacity, Is.EqualTo(0)); a.Add(new Mammal("1")); Assert.Throws <ArgumentException>(() => a.Capacity = 0); a.Add(new Mammal("2")); a.Add(new Mammal("3")); a.Add(new Mammal("4")); a.Add(new Mammal("5")); Assert.That(a.Capacity, Is.EqualTo(8)); a.Capacity = 5; Assert.That(a.Capacity, Is.EqualTo(5)); a.Add(new Mammal("6")); a.Add(new Mammal("7")); a.Add(new Mammal("8")); a.Add(new Mammal("9")); a.Add(new Mammal("10")); Assert.That(a.Capacity, Is.EqualTo(10)); a.Clear(); Assert.That(a.Capacity, Is.EqualTo(10)); }
public void SortedArrayListAllowDuplicatesTest() { var b = new CKSortedArrayList <int>(true); b.AddRangeArray(12, -34, 7, 545, 12); b.AllowDuplicates.Should().BeTrue(); b.Count.Should().Be(5); b.Should().BeInAscendingOrder(); b.IndexOf(12).Should().Be(2); b.CheckPosition(2).Should().Be(2); b.CheckPosition(3).Should().Be(3); }
public void SortedArrayListAllowDuplicatesTest() { var b = new CKSortedArrayList <int>(true); b.AddRangeArray(12, -34, 7, 545, 12); Assert.That(b.AllowDuplicates, Is.True); Assert.That(b.Count, Is.EqualTo(5)); Assert.That(b, Is.Ordered); Assert.That(b.IndexOf(12), Is.EqualTo(2)); Assert.That(b.CheckPosition(2), Is.EqualTo(2)); Assert.That(b.CheckPosition(3), Is.EqualTo(3)); }
public void Covariance_support_via_ICKReadOnlyList_and_ICKWritableCollection() { var a = new CKSortedArrayList <Mammal>((a1, a2) => a1.Name.CompareTo(a2.Name)); a.Add(new Mammal("B", 12)); a.Add(new Canidae("A", 12, true)); IReadOnlyList <Animal> baseObjects = a; for (int i = 0; i < baseObjects.Count; ++i) { baseObjects[i].Should().BeAssignableTo <Animal>("This does not test anything. It's just to be read."); } ICKWritableCollection <Canidae> dogs = a; dogs.Add(new Canidae("C", 8, false)); }
public void SortedArrayList_can_be_cast_into_IList_or_ICollection() { var a = new CKSortedArrayList <int>(); a.AddRangeArray(12, -34, 7, 545, 12); //Cast IList IList <int> listToTest = (IList <int>)a; listToTest[0].Should().Be(-34); listToTest[1].Should().Be(7); listToTest[2].Should().Be(12); listToTest[3].Should().Be(545); listToTest.Add(12345); listToTest.Add(1234); listToTest[4].Should().Be(1234); listToTest[5].Should().Be(12345); listToTest[0] = -33; listToTest[0].Should().Be(-33); listToTest[0] = 123456; listToTest[0].Should().Be(123456); listToTest.Insert(0, -33); listToTest[0].Should().Be(-33); listToTest.Insert(0, 123456); listToTest[0].Should().Be(123456); //Cast ICollection a.Clear(); a.AddRangeArray(12, -34, 7, 545, 12); ICollection <int> collectionToTest = (ICollection <int>)a; collectionToTest.IsReadOnly.Should().BeFalse(); collectionToTest.Add(123); collectionToTest.Contains(123).Should().BeTrue(); collectionToTest.Contains(-34).Should().BeTrue(); collectionToTest.Contains(7).Should().BeTrue(); }
public void SortedArrayList_can_be_cast_into_IList_or_ICollection() { var a = new CKSortedArrayList <int>(); a.AddRangeArray(12, -34, 7, 545, 12); //Cast IList IList <int> listToTest = (IList <int>)a; Assert.That(listToTest[0], Is.EqualTo(-34)); Assert.That(listToTest[1], Is.EqualTo(7)); Assert.That(listToTest[2], Is.EqualTo(12)); Assert.That(listToTest[3], Is.EqualTo(545)); listToTest.Add(12345); listToTest.Add(1234); Assert.That(listToTest[4], Is.EqualTo(1234)); Assert.That(listToTest[5], Is.EqualTo(12345)); listToTest[0] = -33; Assert.That(listToTest[0], Is.EqualTo(-33)); listToTest[0] = 123456; Assert.That(listToTest[0], Is.EqualTo(123456)); listToTest.Insert(0, -33); Assert.That(listToTest[0], Is.EqualTo(-33)); listToTest.Insert(0, 123456); Assert.That(listToTest[0], Is.EqualTo(123456)); //Cast ICollection a.Clear(); a.AddRangeArray(12, -34, 7, 545, 12); ICollection <int> collectionToTest = (ICollection <int>)a; Assert.That(collectionToTest.IsReadOnly, Is.False); collectionToTest.Add(123); Assert.That(collectionToTest.Contains(123), Is.True); Assert.That(collectionToTest.Contains(-34), Is.True); Assert.That(collectionToTest.Contains(7), Is.True); }
public void testing_expected_Argument_InvalidOperation_and_IndexOutOfRangeException() { var a = new CKSortedArrayList <Mammal>((a1, a2) => a1.Name.CompareTo(a2.Name)); a.Invoking(sut => sut.IndexOf(null)).Should().Throw <ArgumentNullException>(); a.Invoking(sut => sut.IndexOf(null)).Should().Throw <ArgumentNullException>(); a.Invoking(sut => sut.IndexOf <Mammal>(new Mammal("Nothing"), null)).Should().Throw <ArgumentNullException>(); a.Invoking(sut => sut.Add(null)).Should().Throw <ArgumentNullException>(); a.Add(new Mammal("A")); a.Add(new Mammal("B")); a.Invoking(sut => { Mammal test = sut[2]; }).Should().Throw <IndexOutOfRangeException>(); a.Invoking(sut => sut.CheckPosition(2)).Should().Throw <IndexOutOfRangeException>(); a.Invoking(sut => { Mammal test = a[-1]; }).Should().Throw <IndexOutOfRangeException>(); //Enumerator Exception var enumerator = a.GetEnumerator(); enumerator.Invoking(sut => { Mammal temp = sut.Current; }).Should().Throw <InvalidOperationException>(); enumerator.MoveNext(); enumerator.Current.Should().Be(a[0]); enumerator.Reset(); enumerator.Invoking(sut => { Mammal temp = sut.Current; }).Should().Throw <InvalidOperationException>(); a.Clear(); //change _version enumerator.Invoking(sut => sut.Reset()).Should().Throw <InvalidOperationException>(); enumerator.Invoking(sut => sut.MoveNext()).Should().Throw <InvalidOperationException>(); //Exception IList <Mammal> testException = new CKSortedArrayList <Mammal>(); testException.Add(new Mammal("Nothing")); testException.Invoking(sut => sut[-1] = new Mammal("A")).Should().Throw <IndexOutOfRangeException>(); testException.Invoking(sut => sut[1] = new Mammal("A")).Should().Throw <IndexOutOfRangeException>(); testException.Invoking(sut => sut[0] = null).Should().Throw <ArgumentNullException>(); testException.Invoking(sut => sut.Insert(-1, new Mammal("A"))).Should().Throw <IndexOutOfRangeException>(); testException.Invoking(sut => sut.Insert(2, new Mammal("A"))).Should().Throw <IndexOutOfRangeException>(); testException.Invoking(sut => sut.Insert(0, null)).Should().Throw <ArgumentNullException>(); }
public void testing_expected_Argument_InvalidOperation_and_IndexOutOfRangeException() { var a = new CKSortedArrayList <Mammal>((a1, a2) => a1.Name.CompareTo(a2.Name)); Assert.Throws <ArgumentNullException>(() => a.IndexOf(null)); Assert.Throws <ArgumentNullException>(() => a.IndexOf <Mammal>(new Mammal("Nothing"), null)); Assert.Throws <ArgumentNullException>(() => a.Add(null)); a.Add(new Mammal("A")); a.Add(new Mammal("B")); Assert.Throws <IndexOutOfRangeException>(() => { Mammal test = a[2]; }); Assert.Throws <IndexOutOfRangeException>(() => a.CheckPosition(2)); Assert.Throws <IndexOutOfRangeException>(() => { Mammal test = a[-1]; }); Assert.Throws <IndexOutOfRangeException>(() => a.CheckPosition(-1)); //Enumerator Exception var enumerator = a.GetEnumerator(); Assert.Throws <InvalidOperationException>(() => { Mammal temp = enumerator.Current; }); enumerator.MoveNext(); Assert.That(enumerator.Current, Is.EqualTo(a[0])); enumerator.Reset(); Assert.Throws <InvalidOperationException>(() => { Mammal temp = enumerator.Current; }); a.Clear(); //change _version Assert.Throws <InvalidOperationException>(() => enumerator.Reset()); Assert.Throws <InvalidOperationException>(() => enumerator.MoveNext()); //Exception IList <Mammal> testException = new CKSortedArrayList <Mammal>(); testException.Add(new Mammal("Nothing")); Assert.Throws <IndexOutOfRangeException>(() => testException[-1] = new Mammal("A")); Assert.Throws <IndexOutOfRangeException>(() => testException[1] = new Mammal("A")); Assert.Throws <ArgumentNullException>(() => testException[0] = null); Assert.Throws <IndexOutOfRangeException>(() => testException.Insert(-1, new Mammal("A"))); Assert.Throws <IndexOutOfRangeException>(() => testException.Insert(2, new Mammal("A"))); Assert.Throws <ArgumentNullException>(() => testException.Insert(0, null)); }
public bool MoveNext() { if (_readers == null) { if (_files.Count == 0) { return(false); } _readers = new CKSortedArrayList <OneLogReader>(OneLogReader.CompareHeadTime, allowDuplicates: true); foreach (var r in _files.Where(occ => occ.LastEntryTime >= _firstLogTime).Select(occ => new OneLogReader(occ, _firstLogTime))) { _readers.Add(r); } if (_readers.Count == 0) { return(false); } RemoveAllDuplicates(); Debug.Assert(_readers.Count > 0); return(true); } if (_readers.Count == 0) { return(false); } if (!_readers[0].Forward()) { _readers.RemoveAt(0); return(_readers.Count > 0); } else { RemoveDuplicateAround(_readers.CheckPosition(0)); Debug.Assert(_readers.Count > 0); return(true); } }
protected override void InternalPreCompute() { _serviceVertices = new CKSortedArrayKeyList <YodiiGraphVertex, IServiceInfo>( s => s.LabServiceInfo.ServiceInfo, (a, b) => String.Compare(a.ServiceFullName, b.ServiceFullName), false ); _pluginVertices = new CKSortedArrayKeyList <YodiiGraphVertex, IPluginInfo>( s => s.LabPluginInfo.PluginInfo, (a, b) => String.Compare(a.PluginFullName, b.PluginFullName), false ); _rootFamilies = new CKSortedArrayList <ServiceFamily>( (a, b) => String.Compare(a.RootService.ServiceFullName, b.RootService.ServiceFullName), false ); _serviceFamilies = new CKSortedArrayKeyList <ServiceFamily, IServiceInfo>( s => s.RootService, (a, b) => String.Compare(a.ServiceFullName, b.ServiceFullName), false ); _orphanPlugins = new CKSortedArrayKeyList <YodiiGraphVertex, IPluginInfo>( p => p.LabPluginInfo.PluginInfo, (a, b) => String.Compare(a.PluginFullName, b.PluginFullName), false ); _rootFamilies = new CKSortedArrayList <ServiceFamily>( (a, b) => String.Compare(a.RootService.ServiceFullName, b.RootService.ServiceFullName), false ); }