public void CopyTo_NegativeIndexOfInsertingCollectionInArray_ExceptionThrown() { var list = new List<int>(); for (var i = 0; i < 5; i++) list.Add(i); var intArray = new int[10]; list.CopyTo(intArray, -2); }
public void TestCopyTo_IEnumerable_DestinationSmaller_StopsPrematurely() { IEnumerable<int> source = new List<int>() { 1, 2, 3, 4, 5, 6 }; var destination = TestHelper.Wrap(new List<int>() { 0, 0, 0 }); int index = source.CopyTo(destination); Assert.AreEqual(destination.Count, index, "The wrong index was returned."); var expected = new int[] { 1, 2, 3 }; Assert.IsTrue(expected.ToSublist().IsEqualTo(destination), "The items were not copied as expected."); TestHelper.CheckHeaderAndFooter(destination); }
public void CopyTo_CopyingInNullArray_ExceptionThrown() { var list = new List<int>(); for (var i = 0; i < 5; i++) list.Add(i); int[] intArray = null; list.CopyTo(destinationArray: intArray, indexForInsertingDestinationArray: 1); }
public void CopyTo_ListIsNotPlacedInLengthOfArray_ExceptionThrown() { var list = new List<int>(); for (var i = 0; i < 5; i++) list.Add(i); var intArray = new int[10]; list.CopyTo(intArray, 8); }
public void CopyTo_IndexOutsideAllowableRangeWhenCopyingInArray_ExceptionThrown() { var list = new List<int>(); for (var i = 0; i < 5; i++) list.Add(i); var intArray = new int[10]; list.CopyTo(intArray, 8); }
public void CopyTo_ArrayIsProperlyChanged_AfterCopyingFromList() { var list = new List<int>(); for (var i = 0; i < 5; i++) list.Add(i); var intArray = new int[10]; list.CopyTo(intArray, 2); Assert.AreEqual(1, intArray[3]); }
public void CopyTo_CorrectCopyingOfArray() { var list = new List<int>(); for (var i = 0; i < 5; i++) list.Add(i); var intArray = new int[10]; list.CopyTo(intArray, 2); Assert.AreEqual(1, intArray[3]); }
public void IListExtensions_FisherYatesShuffleRandomizes() { List<int> testInts = new List<int>(Enumerable.Range(0, 100)); int[] orderBeforeShuffle = new int[100]; for (int i = 0; i < 50; i++) { testInts.CopyTo(orderBeforeShuffle); testInts.FisherYatesShuffle(); Assert.IsFalse(orderBeforeShuffle.SequenceEqual(testInts)); } }
public void testListOfSymbolsClone() { List<Symbol> l = new List<Symbol>(); l.Add(new Symbol("A")); l.Add(new Symbol("B")); l.Add(new Symbol("C")); Symbol[] copy = new Symbol[l.Count]; l.CopyTo(copy); List<Symbol> l2 = copy.ToList<Symbol>(); l2.Remove(new Symbol("B")); Assert.AreEqual(3, l.Count); Assert.AreEqual(2, l2.Count); }
public void TcpReceiveEndpointSingleByteDelimitersTest() { var options = new TcpReceieveOptions(); TcpReceiveEndpoint endpoint = new TcpReceiveEndpoint(new IPEndPoint(IPAddress.Any, 6789), options); var host = new Mock<IApplicationHost>(); endpoint.Initialize(host.Object, options); StateObject state = new StateObject(null); List<byte> data = new List<byte>(); data.AddRange(new byte[] { TcpReceieveOptions.SOH }); data.AddRange(new byte[] { TcpReceieveOptions.STX, 0x41, 0x41, 0x41, 0x41, TcpReceieveOptions.ETX }); data.AddRange(new byte[] { TcpReceieveOptions.EOT }); data.CopyTo(state.Buffer, 0); bool isEot = endpoint.ProcessIncomingStream(state.Buffer.Length, state); Assert.IsTrue(isEot); host.Verify(app => app.ProcessInPipeline(It.IsAny<TcpReceiveEndpoint>(), It.IsNotNull<byte[]>()), Times.Once); host.Verify(app => app.ProcessInPipeline(It.IsAny<TcpReceiveEndpoint>(), It.Is<byte[]>(indata => indata.SequenceEqual(new byte[] { 0x41, 0x41, 0x41, 0x41 })))); }
public void TestCopyTo_IEnumerable_NullDestination_Throws() { IEnumerable<int> source = new List<int>(); IExpandableSublist<List<int>, int> destination = null; source.CopyTo(destination); }
public void TestCopyTo_NullDestination_Throws() { IExpandableSublist<List<int>, int> list = new List<int>().ToSublist(); IExpandableSublist<List<int>, int> destination = null; list.CopyTo(destination); }
public void TcpReceiveEndpointMultiByteDelimitersTest() { var options = new TcpReceieveOptions(); options.SohDelimiters = new byte[] { TcpReceieveOptions.SOH, 0x06 }; options.StxDelimiters = new byte[] { TcpReceieveOptions.STX, 0x06 }; options.EtxDelimiters = new byte[] { TcpReceieveOptions.ETX, 0x06 }; options.EotDelimiters = new byte[] { TcpReceieveOptions.EOT, 0x07 }; //BUG: If the end-delimiter of STX and EOT match it will not detect EOT //options.EOTDelimiters = new byte[] {TcpReceiveEndpoint.EOT, 0x06}; TcpReceiveEndpoint endpoint = new TcpReceiveEndpoint(new IPEndPoint(IPAddress.Any, 6789), options); var host = new Mock<IApplicationHost>(); endpoint.Initialize(host.Object, options); StateObject state = new StateObject(null); List<byte> data = new List<byte>(); data.AddRange(options.SohDelimiters); data.AddRange(options.StxDelimiters); data.AddRange(new byte[] { 0x41, 0x41, 0x41, 0x41 }); data.AddRange(options.EtxDelimiters); data.AddRange(options.EotDelimiters); data.CopyTo(state.Buffer, 0); bool isEot = endpoint.ProcessIncomingStream(state.Buffer.Length, state); Assert.IsTrue(isEot); host.Verify(app => app.ProcessInPipeline(It.IsAny<TcpReceiveEndpoint>(), It.IsNotNull<byte[]>()), Times.Once); host.Verify(app => app.ProcessInPipeline(It.IsAny<TcpReceiveEndpoint>(), It.Is<byte[]>(indata => indata.SequenceEqual(new byte[] { 0x41, 0x41, 0x41, 0x41 })))); }
public void TcpReceiveEndpointMultiByteDelimitersSplittedBufferTest() { var options = new TcpReceieveOptions(); options.SohDelimiters = new byte[] { TcpReceieveOptions.SOH, 0x06 }; options.StxDelimiters = new byte[] { TcpReceieveOptions.STX, 0x06 }; options.EtxDelimiters = new byte[] { TcpReceieveOptions.ETX, 0x06 }; options.EotDelimiters = new byte[] { TcpReceieveOptions.EOT, 0x07 }; TcpReceiveEndpoint endpoint = new TcpReceiveEndpoint(new IPEndPoint(IPAddress.Any, 6789), options); var host = new Mock<IApplicationHost>(); endpoint.Initialize(host.Object, options); StateObject state = new StateObject(null); List<byte> data = new List<byte>(); data.AddRange(options.SohDelimiters); data.AddRange(options.StxDelimiters); data.AddRange(new byte[] { 0x41, 0x41, 0x41, 0x41 }); data.AddRange(options.EtxDelimiters); data.AddRange(options.EotDelimiters); bool isEot = false; for (int i = 0; i < data.Count; i++) { state.State = StateObject.FrameState.FindSoh; int noBytesInFirstBuffer = i; data.CopyTo(0, state.Buffer, 0, noBytesInFirstBuffer); isEot = endpoint.ProcessIncomingStream(noBytesInFirstBuffer, state); Assert.IsFalse(isEot); data.CopyTo(noBytesInFirstBuffer, state.Buffer, 0, data.Count - noBytesInFirstBuffer); isEot = endpoint.ProcessIncomingStream(data.Count - noBytesInFirstBuffer, state); Assert.IsTrue(isEot); } host.Verify(app => app.ProcessInPipeline(It.IsAny<TcpReceiveEndpoint>(), It.IsNotNull<byte[]>()), Times.AtLeast(3)); host.Verify(app => app.ProcessInPipeline(It.IsAny<TcpReceiveEndpoint>(), It.Is<byte[]>(indata => indata.SequenceEqual(new byte[] { 0x41, 0x41, 0x41, 0x41 })))); }
private void LerPesosAbscissasETempos(string nomeDoArquivo, int nPassos, out double[] tempo, out List<double[]> pesosOuAbscissas) { List<double> tempos = new List<double>(); List<double[]> pesosOuAbscissasT = new List<double[]>(); pesosOuAbscissas = new List<double[]>(); var reader = new StreamReader(@"C:\Users\uqk2\Desktop\" + nomeDoArquivo + ".m"); reader.ReadLine(); reader.ReadLine(); reader.ReadLine(); reader.ReadLine(); while (!reader.EndOfStream) { var linha = reader.ReadLine(); if (linha != null && linha.Contains("%")) { List<double> listaPesosOuAbscissas = new List<double>(); for (int i = 0; i < nPassos; i++) { linha = reader.ReadLine(); if (linha.Contains("%")) linha = reader.ReadLine(); ; int indiceIgual = linha.IndexOf("="); if (linha.Contains("t")) { linha = linha.Trim(); int length = linha.Length - indiceIgual - 1; linha = linha.Substring(indiceIgual + 1, length); linha = linha.Replace(";", ""); tempos.Add(Convert.ToDouble(linha)); } else if (linha.Contains("pN")) { linha = linha.Trim(); int length = linha.Length - indiceIgual - 1; linha = linha.Substring(indiceIgual + 1, length); linha = linha.Replace(";", ""); listaPesosOuAbscissas.Add(Convert.ToDouble(linha)); } else if (linha.Contains("aN")) { linha = linha.Trim(); int length = linha.Length - indiceIgual - 1; linha = linha.Substring(indiceIgual + 1, length); linha = linha.Replace(";", ""); listaPesosOuAbscissas.Add(Convert.ToDouble(linha)); } else break; } if ((!linha.Contains("%")) && (listaPesosOuAbscissas.Count > 0)) { double[] p = new double[listaPesosOuAbscissas.Count]; listaPesosOuAbscissas.CopyTo(p); pesosOuAbscissasT.Add(p); } } else if (linha != null && linha.Contains("hFig")) break; } for (int j = 0; j < tempos.Count; j++) { double[] pp = new double[pesosOuAbscissasT.Count]; for (int i = 0; i < pesosOuAbscissasT.Count; i++) { pp[i] = pesosOuAbscissasT[i][j]; } pesosOuAbscissas.Add(pp); } tempo = new double[tempos.Count]; tempos.CopyTo(tempo); }
public void testBinaryResolventsOrderDoesNotMatter() { // This is a regression test, to ensure // the ordering of resolvents does not matter. // If the order ends up mattering, then likely // a problem was introduced in the Clause class // unifier, or related class. // Set up the initial set of clauses based on the // loves animal domain as it contains functions // new clauses will always be created (i.e. is an // infinite universe of discourse). FOLKnowledgeBase kb = new FOLKnowledgeBase(DomainFactory .lovesAnimalDomain()); kb .tell("FORALL x (FORALL y (Animal(y) => Loves(x, y)) => EXISTS y Loves(y, x))"); kb .tell("FORALL x (EXISTS y (Animal(y) AND Kills(x, y)) => FORALL z NOT(Loves(z, x)))"); kb.tell("FORALL x (Animal(x) => Loves(Jack, x))"); kb.tell("(Kills(Jack, Tuna) OR Kills(Curiosity, Tuna))"); kb.tell("Cat(Tuna)"); kb.tell("FORALL x (Cat(x) => Animal(x))"); List<Clause> clauses = new List<Clause>(); clauses.AddRange(kb.getAllClauses()); List<Clause> newClauses = new List<Clause>(); long maxRunTime = 30 * 1000; // 30 seconds long finishTime = System.DateTime.UtcNow.Ticks + maxRunTime; do { clauses.AddRange(newClauses); newClauses.Clear(); Clause[] clausesA = new Clause[clauses.Count]; clauses.CopyTo(clausesA); for (int i = 0; i < clausesA.Length; i++) { Clause cI = clausesA[i]; for (int j = 0; j < clausesA.Length; j++) { Clause cJ = clausesA[j]; newClauses.AddRange(cI.getFactors()); newClauses.AddRange(cJ.getFactors()); List<Clause> cIresolvents = cI.binaryResolvents(cJ); List<Clause> cJresolvents = cJ.binaryResolvents(cI); if (!cIresolvents.Equals(cJresolvents)) { System.Console.WriteLine("cI=" + cI); System.Console.WriteLine("cJ=" + cJ); System.Console.WriteLine("cIR=" + cIresolvents); System.Console.WriteLine("cJR=" + cJresolvents); Assert .Fail("Ordering of binary resolvents has become usingant, which should not be the case"); } foreach (Clause r in cIresolvents) { newClauses.AddRange(r.getFactors()); } if (System.DateTime.UtcNow.Ticks > finishTime) { break; } } if (System.DateTime.UtcNow.Ticks > finishTime) { break; } } } while (System.DateTime.UtcNow.Ticks < finishTime); }