internal static void valueComparator(RowSet rawrowset, List<object[]> insertedRows) { List<Row> rowset = rawrowset.GetRows().ToList(); Assert.True(rowset.Count == insertedRows.Count, string.Format( "Returned rows count is not equal with the count of rows that were inserted! \n Returned: {0} \n Expected: {1} \n", rowset.Count, insertedRows.Count)); int i = 0; foreach (Row row in rowset) { if (row.Any(col => col.GetType() == typeof (byte[]))) for (int j = 0; j < row.Length; j++) { Assert.AreEqual(insertedRows[i][j], row[j]); } else { for (int m = 0; m < row.Length; m++) { if (!row[m].Equals(insertedRows[i][m])) { insertedRows.Reverse(); // To check if needed and why if (!row[m].Equals(insertedRows[i][m])) insertedRows.Reverse(); } Assert.AreEqual(insertedRows[i][m], row[m], "Inserted data does not match with returned data."); } } i++; } }
public void BeforeClassSorterUtilTest() { // only read the values of the undeleted documents, since after addIndexes, // the deleted ones will be dropped from the index. Bits liveDocs = reader.LiveDocs; List<int> values = new List<int>(); for (int i = 0; i < reader.MaxDoc; i++) { if (liveDocs == null || liveDocs.Get(i)) { values.Add(int.Parse(reader.Document(i).Get(ID_FIELD), CultureInfo.InvariantCulture)); } } int idx = Random().nextInt(SORT.Length); Sort sorter = SORT[idx]; if (idx == 1) { // reverse doc sort values.Reverse(); } else { values.Sort(); if (Random().nextBoolean()) { sorter = new Sort(new SortField(NUMERIC_DV_FIELD, SortField.Type_e.LONG, true)); // descending values.Reverse(); } } sortedValues = values.ToArray(); if (VERBOSE) { Console.WriteLine("sortedValues: " + sortedValues); Console.WriteLine("Sorter: " + sorter); } Directory target = NewDirectory(); using (IndexWriter writer = new IndexWriter(target, NewIndexWriterConfig(TEST_VERSION_CURRENT, null))) { using (reader = SortingAtomicReader.Wrap(reader, sorter)) { writer.AddIndexes(reader); } } dir.Dispose(); // CheckIndex the target directory dir = target; TestUtil.CheckIndex(dir); // set reader for tests reader = SlowCompositeReaderWrapper.Wrap(DirectoryReader.Open(dir)); assertFalse("index should not have deletions", reader.HasDeletions); }
public void TestGetPreviousTokenIncludingSkippedTokens() { var text = @"cbuffer Globals { int a; garbage int b; }"; var tree = SyntaxFactory.ParseSyntaxTree(SourceText.From(text)); Assert.AreEqual(text, tree.Root.ToFullString()); var tokens = tree.Root.DescendantTokens(descendIntoTrivia: true).Where(t => t.Span.Length > 0).ToList(); Assert.AreEqual(11, tokens.Count); Assert.AreEqual("garbage", tokens[6].Text); var list = new List<SyntaxToken>(tokens.Count); var token = tree.Root.GetLastToken(includeSkippedTokens: true); while (token != null) { list.Add(token); token = token.GetPreviousToken(includeSkippedTokens: true); } list.Reverse(); Assert.AreEqual(tokens.Count, list.Count); for (int i = 0; i < tokens.Count; i++) { Assert.AreEqual(list[i], tokens[i]); } }
public void WontUpdateIfNoChangeInReferencesTest() { var from = FileHelper.ResourceFileFor<VSProjectTest>("before.csproj.xml"); var projFile = FileHelper.CopyToTmpFile(from); var proj = VSProject.FromPath(projFile); var resources = new List<VSProject.Reference> { new VSProject.Reference{Include="MyChildArtifactId1", HintPath="%CACHE_PATH%\\path\\to\\child1.ext"}, new VSProject.Reference{Include="MyChildArtifactId2",HintPath="%CACHE_PATH%\\path\\to\\child2.ext"} }; var changed1stTime = proj.UpdateReferences(resources); Assert.True(changed1stTime); var orgWriteTime = projFile.LastWriteTime; //wait a bit to let clock tick Thread.Sleep(TimeSpan.FromSeconds(1)); //force an update, shou6ld check if already exist resources.Reverse(); var changed2ndTime = proj.UpdateReferences(resources); var newWriteTime = projFile.LastWriteTime; Assert.False(changed2ndTime); Assert.AreEqual(orgWriteTime, newWriteTime); projFile.Delete(); }
private List<CodecMatch> GetSoretedList(params CodecMatch[] codecs) { var list = new List<CodecMatch>(); list.AddRange(codecs); list.Sort(); list.Reverse();//we want from higher to smaller return list; }
public void ReversedList() { // Note: mustn't give source a compile-time type of List<int> as // List<T> has a Reverse method. IEnumerable<int> source = new List<int> { 5, 6, 7, 8, 9 }; var query = source.Reverse(); query.AssertSequenceEqual(9, 8, 7, 6, 5); }
public void ReverseQueryReuse() { List<int> data = new List<int> { 1, 2, 3 }; IEnumerable<int> enumerable = data.Reverse<int>(); // # Using Reverse<int> (with type parameter) in order to avoid calling List<int>.Reverse() enumerable.AssertEqual(3, 2, 1); data.Add(4); enumerable.AssertEqual(4, 3, 2, 1); }
public void Reverse_Iterator_Is_Inverse_of_Forward_Iterator() { List<DataTable> forwardItems = new List<DataTable>(); foreach (DataTable dt in _forwardIterator) { forwardItems.Add(dt); } forwardItems.Reverse(); Assert.That(forwardItems, Is.EquivalentTo(_reverseIterator)); }
public void Arrange() { //_originalValues = new List<String>{"BankVue", "Should", "Hire", "Elliott"}; // lets check some performance issues _originalValues = new List<string>(); for (var i = 0; i < 1000000; i++ ) { _originalValues.Add(Guid.NewGuid().ToString()); } _list = new CheatingLinkedList<String>(); _expectedValues = new List<String>(_originalValues); _expectedValues.Reverse(); }
public IEnumerable<int> Get1sInNumber(int length, int perm) { int digit = 0; List<int> result = new List<int>(); while (perm > 0) { if ((perm & 1) == 1) result.Add(digit); digit++; perm /= 2; } result.Reverse(); return result.Select(o => length - o - 1); }
public void DifferShouldDiffArraysByObjectEqualityByDefault() { IEnumerable<TestObj> array = new List<TestObj> { new TestObj { Id = 1 }, new TestObj { Id = 2 } }; var diff = _differ.Diff(array, array.Reverse()); Assert.IsNull(diff); }
public void Prepend_ToList() { Tuple<Table<EntityWithListType>, List<EntityWithListType>> tupleListType = EntityWithListType.SetupDefaultTable(_session); Table<EntityWithListType> table = tupleListType.Item1; List<EntityWithListType> expectedEntities = tupleListType.Item2; List<int> listToAdd = new List<int> { -1, 0, 5, 6 }; List<int> listReversed = new List<int>(listToAdd); listReversed.Reverse(); EntityWithListType singleEntity = expectedEntities.First(); EntityWithListType expectedEntity = singleEntity.Clone(); expectedEntity.ListType.InsertRange(0, listReversed); // Append the values table.Where(t => t.Id == singleEntity.Id).Select(t => new EntityWithListType { ListType = CqlOperator.Prepend(listToAdd) }).Update().Execute(); // Validate final state of the data var entityList = table.Where(m => m.Id == singleEntity.Id).ExecuteAsync().Result.ToList(); Assert.AreEqual(1, entityList.Count); Assert.AreNotEqual(expectedEntity.ListType, singleEntity.ListType); expectedEntity.AssertEquals(entityList[0]); }
public void EncodingTypeCompare() { List<EncodingType> list = new List<EncodingType>( new EncodingType[] { EncodingType.Parse("identity;q=0.5"), EncodingType.Parse("*;q=0"), EncodingType.Parse("gzip;q=1.0") }); list.Sort(); list.Reverse(); Assert.AreEqual("gzip", list[0].ToString()); Assert.AreEqual("identity;q=0.5", list[1].ToString()); Assert.AreEqual("*;q=0", list[2].ToString()); Assert.IsTrue(EncodingType.Empty > (EncodingType)null); Assert.IsTrue(EncodingType.Parse("gzip") > EncodingType.Parse("gzip;q=0.5")); Assert.IsTrue((EncodingType)null < EncodingType.Empty); Assert.IsTrue(EncodingType.Parse("gzip;q=0.5") < EncodingType.Parse("gzip")); }
public void DifferShouldDiffObjectArrayElementsByIndexWhenUsingIndexEnumerableDiffer() { var differ = GetDiffer(true); var obj1 = new TestObj { Id = 1 }; var obj2 = new TestObj { Id = 2 }; IEnumerable<TestObj> array = new List<TestObj> { obj1, obj2 }; // should return 2 child diffs, one for each array element, even though the elements in each array are equal var diff = differ.Diff(array, array.Reverse()); Assert.AreEqual(2, diff.ChildDiffs.Count()); Assert.IsTrue(diff.ChildDiffs.Any(d => d.NewValue == obj1 && d.OldValue == obj2)); Assert.IsTrue(diff.ChildDiffs.Any(d => d.NewValue == obj2 && d.OldValue == obj1)); }
public void query_paged_post_test() { var authorId = ObjectId.GenerateNewStringId(); var subject = ObjectId.GenerateNewStringId(); var body = ObjectId.GenerateNewStringId(); var sectionId = ObjectId.GenerateNewStringId(); var postIds = new List<string>(); var totalPostCount = 10; var replyCountPerPost = 2; var pageSize = 2; for (var i = 0; i < totalPostCount; i++) { var postId = ExecuteCommand(new CreatePostCommand(subject, body, sectionId, authorId)).AggregateRootId; for (var j = 0; j < replyCountPerPost; j++) { ExecuteCommand(new CreateReplyCommand(postId, null, body, authorId)); } postIds.Add(postId); } postIds.Reverse(); var queryService = ObjectContainer.Resolve<IPostQueryService>(); for (var pageIndex = 1; pageIndex <= totalPostCount / pageSize; pageIndex++) { var posts = queryService.Find(new PostQueryOption { SectionId = sectionId, PageInfo = new PageInfo { PageIndex = pageIndex, PageSize = pageSize } }).Posts.ToList(); Assert.AreEqual(replyCountPerPost, posts.Count()); var expectedPostIds = postIds.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList(); for (var i = 0; i < pageSize; i++) { Assert.AreEqual(expectedPostIds[i], posts[i].Id); Assert.AreEqual(replyCountPerPost, posts[i].ReplyCount); } } }
public void RemovePUT2(int initialSize, int removePosition) { PexAssume.IsTrue((initialSize >= MIN && initialSize <= MAX) || (initialSize < MIN) || (initialSize > MAX)); PexAssume.IsTrue(initialSize >= MIN && initialSize <= MAX); PexAssume.IsTrue(removePosition >= 1 && removePosition < initialSize); if ((initialSize >= MIN && initialSize <= MAX)) { recentFiles.MaxFiles = initialSize; } else if (initialSize < MIN) { recentFiles.MaxFiles = initialSize; } else { recentFiles.MaxFiles = initialSize; } List<int> oracleList = new List<int>(); for (int num = 1; num <= initialSize; ++num) { recentFiles.SetMostRecent(num.ToString()); recentFiles.SetMostRecent(num.ToString()); oracleList.Add(num); } oracleList.Reverse(); Random random = new Random(); for (int num = 0; num < removePosition; num++) { int randomNo = random.Next(0, initialSize); int elemToRemove = oracleList[randomNo]; oracleList.Remove(elemToRemove); recentFiles.Remove(elemToRemove.ToString()); initialSize--; } //Asserting the behavior for (int count = 0; count < initialSize - 1; count++) { PexAssert.AreEqual(recentFiles.Entries[count].Path, oracleList[count] + ""); } }
public void CanEnumerateCommitsWithReverseTimeSorting() { var reversedShas = new List<string>(expectedShas); reversedShas.Reverse(); int count = 0; using (var repo = new Repository(BareTestRepoPath)) { foreach (Commit commit in repo.Commits.QueryBy(new Filter { Since = "a4a7dce85cf63874e984719f4fdd239f5145052f", SortBy = GitSortOptions.Time | GitSortOptions.Reverse })) { commit.ShouldNotBeNull(); commit.Sha.StartsWith(reversedShas[count]).ShouldBeTrue(); count++; } } count.ShouldEqual(6); }
public void TestReverse() { // 暂时 复制 数据列表. List<TestData> tempList = new List<TestData>(); foreach (TestData data in dataList) { tempList.Add(data); } // 反转前 Assert.AreEqual(4, tempList[0].ID); Assert.AreEqual(3, tempList[1].ID); Assert.AreEqual(2, tempList[2].ID); Assert.AreEqual(1, tempList[3].ID); // 反转. tempList.Reverse(); // 反转后. Assert.AreEqual(1, tempList[0].ID); Assert.AreEqual(2, tempList[1].ID); Assert.AreEqual(3, tempList[2].ID); Assert.AreEqual(4, tempList[3].ID); }
public void test_IsSortedStrict_and_IsSortedLarge_extension_methods() { List<int> listWithDuplicate = new List<int>(); listWithDuplicate.AddRangeArray<int>( 1, 2, 2, 3, 3, 5 ); List<int> listWithoutDuplicate = new List<int>(); listWithoutDuplicate.AddRangeArray<int>( 1, 2, 3, 5 ); Assert.That( listWithDuplicate.IsSortedStrict(), Is.False ); Assert.That( listWithDuplicate.IsSortedLarge(), Is.True ); Assert.Throws<ArgumentNullException>( () => listWithDuplicate.IsSortedLarge( null ) ); Assert.Throws<ArgumentNullException>( () => listWithDuplicate.IsSortedStrict( null ) ); Assert.That( listWithoutDuplicate.IsSortedStrict(), Is.True ); Assert.That( listWithoutDuplicate.IsSortedLarge(), Is.True ); Assert.Throws<ArgumentNullException>( () => listWithoutDuplicate.IsSortedLarge( null ) ); Assert.Throws<ArgumentNullException>( () => listWithoutDuplicate.IsSortedStrict( null ) ); listWithDuplicate.Reverse(0, listWithDuplicate.Count); listWithoutDuplicate.Reverse(0, listWithoutDuplicate.Count); Assert.That( listWithDuplicate.IsSortedStrict(), Is.False ); Assert.That( listWithDuplicate.IsSortedLarge(), Is.False ); Assert.That( listWithoutDuplicate.IsSortedStrict(), Is.False ); Assert.That( listWithoutDuplicate.IsSortedLarge(), Is.False ); //test with 2 items listWithoutDuplicate = new List<int>(); listWithoutDuplicate.AddRangeArray<int>( 1, 5 ); Assert.That( listWithoutDuplicate.IsSortedStrict(), Is.True ); Assert.That( listWithoutDuplicate.IsSortedLarge(), Is.True ); listWithDuplicate = new List<int>(); listWithDuplicate.AddRangeArray<int>( 5, 5 ); Assert.That( listWithDuplicate.IsSortedStrict(), Is.False ); Assert.That( listWithDuplicate.IsSortedLarge(), Is.True ); listWithDuplicate.Reverse( 0, listWithDuplicate.Count ); listWithoutDuplicate.Reverse( 0, listWithoutDuplicate.Count ); Assert.That( listWithDuplicate.IsSortedStrict(), Is.False ); Assert.That( listWithDuplicate.IsSortedLarge(), Is.True ); Assert.That( listWithoutDuplicate.IsSortedStrict(), Is.False ); Assert.That( listWithoutDuplicate.IsSortedLarge(), Is.False ); //test with 1 items listWithoutDuplicate = new List<int>(); listWithoutDuplicate.Add( 1 ); Assert.That( listWithoutDuplicate.IsSortedStrict(), Is.True ); Assert.That( listWithoutDuplicate.IsSortedLarge(), Is.True ); //Empty test listWithoutDuplicate = new List<int>(); Assert.That( listWithoutDuplicate.IsSortedStrict(), Is.True ); Assert.That( listWithoutDuplicate.IsSortedLarge(), Is.True ); listWithDuplicate = new List<int>(); Assert.That( listWithoutDuplicate.IsSortedStrict(), Is.True ); Assert.That( listWithoutDuplicate.IsSortedLarge(), Is.True ); listWithDuplicate = null; Assert.Throws<NullReferenceException>( () => listWithDuplicate.IsSortedLarge() ); Assert.Throws<NullReferenceException>( () => listWithDuplicate.IsSortedStrict() ); }
public void MediaTypeCompare() { List<MediaType> list = new List<MediaType>(new MediaType[] { MediaType.Parse("text/*"), MediaType.Parse("text/html"), MediaType.Parse("text/html;level=1"), MediaType.Parse("*/*") }); list.Sort(); list.Reverse(); Assert.AreEqual(MediaType.Parse("text/html;level=1"), list[0]); Assert.AreEqual(MediaType.Parse("text/html"), list[1]); Assert.AreEqual(MediaType.Parse("text/*"), list[2]); Assert.AreEqual(MediaType.Parse("*/*"), list[3]); list.Clear(); list.AddRange( new MediaType[] { MediaType.Parse("text/*;q=0.3"), MediaType.Parse("text/html;q=0.7"), MediaType.Parse("text/html;level=1"), MediaType.Parse("text/html;level=2;q=0.4"), MediaType.Parse("*/*;q=0.5") }); list.Sort(); list.Reverse(); Assert.AreEqual("text/html;level=1", list[0].ToString()); Assert.AreEqual("text/html;q=0.7", list[1].ToString()); Assert.AreEqual("*/*;q=0.5", list[2].ToString()); Assert.AreEqual("text/html;level=2;q=0.4", list[3].ToString()); Assert.AreEqual("text/*;q=0.3", list[4].ToString()); Assert.IsTrue(MediaType.Empty > (MediaType)null); Assert.IsTrue(MediaType.Parse("application/json") > MediaType.Parse("application/json;q=0.5")); Assert.IsTrue((MediaType)null < MediaType.Empty); Assert.IsTrue(MediaType.Parse("application/json;q=0.5") < MediaType.Parse("application/json")); }
public void SingleRightRotationPUT(int root, int left, int right) { PexAssume.IsTrue(left < root && right > root); List<int> list = new List<int> { left, root, right }; list.Sort(); list.Reverse(); PexObserve.ValueForViewing<int[]>("Input list",list.ToArray()); AvlTree<int> avlTree = new AvlTree<int>(list); PexAssert.AreEqual(root, avlTree.Root.Value); PexAssert.AreEqual(left, avlTree.Root.Left.Value); PexAssert.AreEqual(right, avlTree.Root.Right.Value); }
public void checkingOrderOfCollection(string CassandraCollectionType, Type TypeOfDataToBeInputed, Type TypeOfKeyForMap = null, string pendingMode = "") { string cassandraDataTypeName = QueryTools.convertTypeNameToCassandraEquivalent(TypeOfDataToBeInputed); string cassandraKeyDataTypeName = ""; string openBracket = CassandraCollectionType == "list" ? "[" : "{"; string closeBracket = CassandraCollectionType == "list" ? "]" : "}"; string mapSyntax = ""; string randomKeyValue = string.Empty; if (TypeOfKeyForMap != null) { cassandraKeyDataTypeName = QueryTools.convertTypeNameToCassandraEquivalent(TypeOfKeyForMap); mapSyntax = cassandraKeyDataTypeName + ","; if (TypeOfKeyForMap == typeof (DateTimeOffset)) randomKeyValue = Randomm.RandomVal(typeof (DateTimeOffset)) .GetType() .GetMethod("ToString", new[] {typeof (string)}) .Invoke(Randomm.RandomVal(typeof (DateTimeOffset)), new object[1] {"yyyy-MM-dd H:mm:sszz00"}) + "' : '"; else randomKeyValue = Randomm.RandomVal(TypeOfDataToBeInputed) + "' : '"; } string tableName = "table" + Guid.NewGuid().ToString("N"); try { Session.WaitForSchemaAgreement( QueryTools.ExecuteSyncNonQuery(Session, string.Format(@"CREATE TABLE {0}( tweet_id uuid PRIMARY KEY, some_collection {1}<{2}{3}> );", tableName, CassandraCollectionType, mapSyntax, cassandraDataTypeName))); } catch (AlreadyExistsException) { } Guid tweet_id = Guid.NewGuid(); var longQ = new StringBuilder(); longQ.AppendLine("BEGIN BATCH "); int CollectionElementsNo = 100; var orderedAsInputed = new List<Int32>(CollectionElementsNo); string inputSide = "some_collection + {1}"; if (CassandraCollectionType == "list" && pendingMode == "prepending") inputSide = "{1} + some_collection"; for (int i = 0; i < CollectionElementsNo; i++) { int data = i*(i%2); longQ.AppendFormat(@"UPDATE {0} SET some_collection = " + inputSide + " WHERE tweet_id = {2};" , tableName, openBracket + randomKeyValue + data + closeBracket, tweet_id); orderedAsInputed.Add(data); } longQ.AppendLine("APPLY BATCH;"); QueryTools.ExecuteSyncNonQuery(Session, longQ.ToString(), "Inserting..."); if (CassandraCollectionType == "set") { orderedAsInputed.Sort(); orderedAsInputed.RemoveRange(0, orderedAsInputed.LastIndexOf(0)); } else if (CassandraCollectionType == "list" && pendingMode == "prepending") orderedAsInputed.Reverse(); var rs = Session.Execute(string.Format("SELECT * FROM {0};", tableName), Session.Cluster.Configuration.QueryOptions.GetConsistencyLevel()); { int ind = 0; foreach (Row row in rs.GetRows()) foreach (object value in row[1] as IEnumerable) { Assert.True(orderedAsInputed[ind] == (int) value); ind++; } } QueryTools.ExecuteSyncQuery(Session, string.Format("SELECT * FROM {0};", tableName), Session.Cluster.Configuration.QueryOptions.GetConsistencyLevel()); QueryTools.ExecuteSyncNonQuery(Session, string.Format("DROP TABLE {0};", tableName)); }
public void TwoPathsWithTheSamePointsButInDifferentOrderShouldNotBeEquals() { var listPoints = new List<SimplePoint> { new SimplePoint(10, 20), new SimplePoint(15, 20), new SimplePoint(15, 18), new SimplePoint(20, 20), new SimplePoint(15, 25) }; var reversedPointList = listPoints.Reverse<SimplePoint>().ToList(); var testPath1 = new Path(listPoints); var testPath2 = new Path(reversedPointList); testPath1.Equals(testPath2).Should().Be(false); }
public void ConfirmThreeGonRing() { const int limit = 7; var results = new List<string>(); // Three lines which must add up to the same number // ABC,FCD,EDB using the digits 1-9 // Then if all digits placed, starting with the lowest of A, F, E create a number from the line and then go round clockwise for the other three lines for (var a = 1; a < limit; ++a) { for (var b = 1; b < limit; ++b) { if (b == a) continue; for (var c = 1; c < limit; ++c) { if ((c == b) || (c == a)) continue; var firstLineTotal = a + b + c; for (var d = 1; d < limit; ++d) { if ((d == c) || (d == b) || (d == a)) continue; for (var e = 1; e < limit; ++e) { if ((e == d) || (e == c) || (e == b) || (e == a)) continue; var secondLineTotal = e + d + b; if (secondLineTotal != firstLineTotal) continue; for (var f = 1; f < limit; ++f) { if ((f == e) || (f == d) || (f == c) || (f == b) || (f == a)) continue; var thirdLineTotal = f + c + d; if (thirdLineTotal != secondLineTotal) continue; var concatenatedNumber = GetSixNumber(a, b, c, d, e, f); if (!results.Contains(concatenatedNumber)) results.Add(concatenatedNumber); } } } } } } results.Sort(); results.Reverse(); foreach (var result in results) { Console.WriteLine("{0}", result); } Assert.AreEqual(8, results.Count, "Eight solutions"); Assert.AreEqual("432621513", results[0], "Largest solution"); }
public void ReorderPUT2(int initialSize, int reorderPosition) { PexAssume.IsTrue((initialSize >= MIN && initialSize <= MAX) || (initialSize < MIN) || (initialSize > MAX)); PexAssume.IsTrue(reorderPosition >= MIN && reorderPosition <= initialSize); if ((initialSize >= MIN && initialSize <= MAX)) { recentFiles.MaxFiles = initialSize; } else if (initialSize < MIN) { recentFiles.MaxFiles = initialSize; } else { recentFiles.MaxFiles = initialSize; } List<int> oracleList = new List<int>(); for (int num = 1; num <= initialSize; ++num) { recentFiles.SetMostRecent(num.ToString()); recentFiles.SetMostRecent(num.ToString()); oracleList.Add(num); } oracleList.Reverse(); recentFiles.SetMostRecent(reorderPosition.ToString()); oracleList.Remove(reorderPosition); oracleList.Insert(0, reorderPosition); for (int num = 1; num < initialSize; ++num) { Console.WriteLine(recentFiles.Entries[num - 1].Path); } Console.WriteLine("Oracle elements"); for (int num = 0; num < oracleList.Count; ++num) { Console.WriteLine(oracleList[num]); } //Asserting the behavior for (int count = 0; count < initialSize; count++) { PexAssert.AreEqual(recentFiles.Entries[count].Path, oracleList[count] + ""); } }
public void Trim_GivenTrimValue_WhenTrimValueSmallerThanBufferedAmount_ShouldTrimOldest() { //---------------Set up test pack------------------- var sut = Create(); var howMany = RandomValueGen.GetRandomInt(4, 8); var ids = new List<long>(); for (var i = 0; i < howMany; i++) ids.Add(sut.Buffer(RandomValueGen.GetRandomString(10, 10))); ids.Reverse(); var expected = ids.Take(2).ToArray(); //---------------Assert Precondition---------------- Assert.AreEqual(howMany, GetCurrentlyBufferedItemsIn(sut.ConnectionString).Count); //---------------Execute Test ---------------------- sut.Trim(2); //---------------Test Result ----------------------- var remaining = GetCurrentlyBufferedItemsIn(sut.ConnectionString); Assert.AreEqual(2, remaining.Count); var reaminingIds = remaining.Select(r => r.Id).ToArray(); CollectionAssert.AreEquivalent(expected, reaminingIds); }
public void ApplyChanges (List<Change> changes) { changes.Sort ((x, y) => x.Offset.CompareTo (y.Offset)); changes.Reverse (); foreach (var change in changes) { text = text.Substring (0, change.Offset) + change.InsertedText + text.Substring (change.Offset + change.RemovedChars); } delimiters = new List<Delimiter> (FindDelimiter (text)); }
public void TestIntervalTreeFindExactReverseOrder() { List<DateTimeRange> source = new List<DateTimeRange>(); source.Add(MakeRange( "2008-04-21T08:00:00.000Z", "2008-04-21T08:15:00.000Z", DateTimeKind.Local)); source.Add(MakeRange( "2008-04-21T09:15:00.000Z", "2008-04-21T09:30:00.000Z", DateTimeKind.Local)); source.Add(MakeRange( "2008-04-21T10:30:00.000Z", "2008-04-21T10:45:00.000Z", DateTimeKind.Local)); source.Add(MakeRange( "2008-04-21T11:45:00.000Z", "2008-04-21T12:00:00.000Z", DateTimeKind.Local)); source.Add(MakeRange( "2008-04-21T13:00:00.000Z", "2008-04-21T18:00:00.000Z", DateTimeKind.Local)); source.Add(MakeRange( "2008-04-21T14:00:00.000Z", "2008-04-21T15:00:00.000Z", DateTimeKind.Local)); source.Add(MakeRange( "2008-04-21T14:00:00.000Z", "2008-04-21T14:30:00.000Z", DateTimeKind.Local)); source.Add(MakeRange( "2008-04-21T14:30:00.000Z", "2008-04-21T15:00:00.000Z", DateTimeKind.Local)); source.Add(MakeRange( "2008-04-21T15:00:00.000Z", "2008-04-21T17:15:00.000Z", DateTimeKind.Local)); source.Add(MakeRange( "2008-04-21T15:00:00.000Z", "2008-04-21T16:00:00.000Z", DateTimeKind.Local)); source.Add(MakeRange( "2008-04-21T15:30:00.000Z", "2008-04-21T17:45:00.000Z", DateTimeKind.Local)); source.Add(MakeRange( "2008-04-21T16:00:00.000Z", "2008-04-21T17:45:00.000Z", DateTimeKind.Local)); source.Reverse(); List<DateTimeRange> keys = new List<DateTimeRange>(); keys.Add(MakeRange( "2008-04-21T08:00:00.000Z", "2008-04-21T08:15:00.000Z", DateTimeKind.Unspecified)); keys.Add(MakeRange( "2008-04-21T09:15:00.000Z", "2008-04-21T09:30:00.000Z", DateTimeKind.Unspecified)); keys.Add(MakeRange( "2008-04-21T10:30:00.000Z", "2008-04-21T10:45:00.000Z", DateTimeKind.Unspecified)); keys.Add(MakeRange( "2008-04-21T11:45:00.000Z", "2008-04-21T12:00:00.000Z", DateTimeKind.Unspecified)); keys.Add(MakeRange( "2008-04-21T13:00:00.000Z", "2008-04-21T18:00:00.000Z", DateTimeKind.Unspecified)); keys.Add(MakeRange( "2008-04-21T14:00:00.000Z", "2008-04-21T15:00:00.000Z", DateTimeKind.Unspecified)); keys.Add(MakeRange( "2008-04-21T14:00:00.000Z", "2008-04-21T14:30:00.000Z", DateTimeKind.Unspecified)); keys.Add(MakeRange( "2008-04-21T14:30:00.000Z", "2008-04-21T15:00:00.000Z", DateTimeKind.Unspecified)); keys.Add(MakeRange( "2008-04-21T15:00:00.000Z", "2008-04-21T17:15:00.000Z", DateTimeKind.Unspecified)); keys.Add(MakeRange( "2008-04-21T15:00:00.000Z", "2008-04-21T16:00:00.000Z", DateTimeKind.Unspecified)); keys.Add(MakeRange( "2008-04-21T15:30:00.000Z", "2008-04-21T17:45:00.000Z", DateTimeKind.Unspecified)); keys.Add(MakeRange( "2008-04-21T16:00:00.000Z", "2008-04-21T17:45:00.000Z", DateTimeKind.Unspecified)); AddToTree(tree, source); Assert.AreEqual(source.Count, tree.NumNodes); foreach (DateTimeRange r in keys) { DateTimeRange result = tree.FindExact(r); Assert.AreEqual(r, result); } }
public void VirtualPropTest() { // Setup CreateFakeGenreList(); // creates fake list of 4 genres on LangProj var testText = CreateTestText(); // creates IText on LangProj with its IStText. var testStText = testText.ContentsOA; // Get LP Fake Genre list var entireGenreList = Cache.LangProject.GenreListOA.PossibilitiesOS.ToList(); testText.GenresRC.Add(entireGenreList[1]); // Second testText.GenresRC.Add(entireGenreList[2]); // Third var initialSeq = testText.GenresRC.ToList(); // Verify that setup affects our chosen virtual property Assert.AreEqual(2, testStText.GenreCategories.Count, "Wrong number of items on virtual property."); var mdc = Cache.MetaDataCacheAccessor; int virtFlid = mdc.GetFieldId2(testStText.ClassID, "GenreCategories", true); // SUT1 VirtualOrderingServices.SetVO(testStText, virtFlid, initialSeq.Cast<ICmObject>()); // Make sure SUT1 worked Assert.AreEqual(1, m_voRepo.Count, "There ought to be one VO object."); // Setup for SUT2 // Make a sequence in a different order and with an extra item, but missing an original. var newList = new List<ICmObject>(entireGenreList.Cast<ICmObject>()); newList.Reverse(); // now has (Fourth, Third, Second, First) // remove 'Second' (which is now at index=2) newList.RemoveAt(2); // now has (Fourth, Third, First) // SUT2 var resultSeq = VirtualOrderingServices.GetOrderedValue(testStText, virtFlid, newList); // Verify Assert.AreEqual(1, m_voRepo.Count, "There ought to still be one VO object."); // result should be (Third, Fourth, First) var actualList = new List<ICmPossibility> {entireGenreList[2], entireGenreList[3], entireGenreList[0]}; var actualAsObj = actualList.Cast<ICmObject>(); Assert.AreEqual(actualAsObj, resultSeq, "Hvo lists differ."); }
public void FindFiveGonRingMaximum() { const int limit = 11; var results = new List<string>(); // Five lines which must add up to the same number // ABC,DCF,EFG,HGJ,KJB using the digits 1-10 // Then if all digits placed, starting with the lowest of A, D,E,H,K create a number from the line and then go round clockwise for the other lines for (var a = 1; a < limit; ++a) { for (var b = 1; b < limit; ++b) { if (b == a) continue; for (var c = 1; c < limit; ++c) { if ((c == b) || (c == a)) continue; var firstLineTotal = a + b + c; for (var d = 1; d < limit; ++d) { if ((d == c) || (d == b) || (d == a)) continue; for (var e = 1; e < limit; ++e) { if ((e == d) || (e == c) || (e == b) || (e == a)) continue; for (var f = 1; f < limit; ++f) { if ((f == e) || (f == d) || (f == c) || (f == b) || (f == a)) continue; var secondLineTotal = d + c + f; if (secondLineTotal != firstLineTotal) continue; for (var g = 1; g < limit; ++g) { if ((g == f) || (g == e) || (g == d) || (g == c) || (g == b) || (g == a)) continue; var thirdLineTotal = e + f + g; if (thirdLineTotal != secondLineTotal) continue; for (var h = 1; h < limit; ++h) { if ((h == g) || (h == f) || (h == e) || (h == d) || (h == c) || (h == b) || (h == a)) continue; for (var j = 1; j < limit; ++j) { if ((j == h) || (j == g) || (j == f) || (j == e) || (j == d) || (j == c) || (j == b) || (j == a)) continue; var fourthLineTotal = h + g + j; if (fourthLineTotal != thirdLineTotal) continue; for (var k = 1; k < limit; ++k) { if ((k == j) || (k == h) || (k == g) || (k == f) || (k == e) || (k == d) || (k == c) || (k == b) || (k == a)) continue; var fifthLineTotal = k + j + b; if (fifthLineTotal != fourthLineTotal) continue; var concatenatedNumber = GetTenNumber(a, b, c, d, e, f, g, h, j, k).PadLeft(20, '0'); if (!results.Contains(concatenatedNumber)) results.Add(concatenatedNumber); } } } } } } } } } } results.Sort(); results.Reverse(); foreach (var result in results) { Console.WriteLine("{0}", result); } results.Should().Contain("00006531031914842725"); }