forked from aalhour/C-Sharp-Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed Issue aalhour#137 Items are not always added to a SkipList
- Loading branch information
Showing
3 changed files
with
97 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,92 @@ | ||
using DataStructures.Lists; | ||
using System.Collections.Generic; | ||
using DataStructures.Lists; | ||
using Xunit; | ||
|
||
namespace UnitTest.DataStructuresTests | ||
{ | ||
public static class SkipListTest | ||
{ | ||
[Fact] | ||
public static void DoTest() | ||
public static void AddOneElement() | ||
{ | ||
var skipList = new SkipList<int>(); | ||
|
||
for (int i = 100; i >= 50; --i) | ||
skipList.Add(i); | ||
skipList.Add(10); | ||
|
||
for (int i = 0; i <= 35; ++i) | ||
skipList.Add(i); | ||
Assert.True(skipList.Count == 1); | ||
Assert.Contains(10, skipList); | ||
} | ||
|
||
for (int i = -15; i <= 0; ++i) | ||
skipList.Add(i); | ||
[Fact] | ||
public static void AddBatchOfElements() | ||
{ | ||
var skipList = new SkipList<int>(); | ||
|
||
for (int i = -15; i >= -35; --i) | ||
for (int i = 100; i > 50; --i) | ||
{ | ||
skipList.Add(i); | ||
} | ||
|
||
Assert.True(skipList.Count == 124); | ||
Assert.True(skipList.Count == 50); | ||
for (int i = 100; i > 50; --i) | ||
{ | ||
Assert.Contains(i, skipList); | ||
} | ||
} | ||
|
||
skipList.Clear(); | ||
[Fact] | ||
public static void AddThreeElementsRemoveOneElement() | ||
{ | ||
var skipList = new SkipList<int>(); | ||
|
||
skipList.Add(1); | ||
skipList.Add(2); | ||
skipList.Add(3); | ||
skipList.Remove(2); | ||
|
||
Assert.True(skipList.Count == 2); | ||
Assert.Contains(1, skipList); | ||
Assert.Contains(3, skipList); | ||
Assert.DoesNotContain(2, skipList); | ||
} | ||
|
||
for (int i = 100; i >= 0; --i) | ||
[Fact] | ||
public static void AddAndRemoveBatchOfElements() | ||
{ | ||
var skipList = new SkipList<int>(); | ||
|
||
for (int i = 100; i > 50; --i) | ||
{ | ||
skipList.Add(i); | ||
} | ||
|
||
for (int i = 100; i > 50; --i) | ||
{ | ||
skipList.Remove(i); | ||
} | ||
|
||
Assert.True(skipList.Count == 0); | ||
for (int i = 100; i > 50; --i) | ||
{ | ||
Assert.DoesNotContain(i, skipList); | ||
} | ||
} | ||
|
||
[Fact] | ||
public static void ClearList() | ||
{ | ||
var skipList = new SkipList<int>(); | ||
|
||
skipList.Add(1); | ||
skipList.Add(2); | ||
skipList.Add(3); | ||
skipList.Clear(); | ||
|
||
Assert.True(skipList.Count == 101); | ||
Assert.True(skipList.Count == 0); | ||
Assert.True(skipList.IsEmpty); | ||
Assert.DoesNotContain(1, skipList); | ||
Assert.DoesNotContain(2, skipList); | ||
Assert.DoesNotContain(3, skipList); | ||
} | ||
} | ||
} |