-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add routine for mapping unique entries in array potentially containin…
…g duplicates/nonconsecutive entries to consecutive integers.
- Loading branch information
Showing
2 changed files
with
70 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/env python | ||
|
||
from unittest import main, TestCase | ||
|
||
import nk.tools.misc as misc | ||
|
||
class test_misc(TestCase): | ||
def test_no_duplicates_consecutive_in_order(self): | ||
result = misc.renumber_in_order([0, 1, 2]) | ||
self.assertSequenceEqual(result, | ||
[0, 1, 2]) | ||
|
||
def test_no_duplicates_nonconsecutive_in_order(self): | ||
result = misc.renumber_in_order([0, 2, 4]) | ||
self.assertSequenceEqual(result, | ||
[0, 1, 2]) | ||
|
||
def test_duplicates_consecutive_in_order(self): | ||
result = misc.renumber_in_order([0, 0, 1, 2, 2, 3]) | ||
self.assertSequenceEqual(result, | ||
[0, 0, 1, 2, 2, 3]) | ||
|
||
def test_duplicates_nonconsecutive_in_order(self): | ||
result = misc.renumber_in_order([0, 0, 2, 3, 3, 5]) | ||
self.assertSequenceEqual(result, | ||
[0, 0, 1, 2, 2, 3]) | ||
|
||
def test_duplicates_nonconsecutive_out_of_order(self): | ||
result = misc.renumber_in_order([0, 3, 1, 1, 2, 3]) | ||
self.assertSequenceEqual(result, | ||
[0, 1, 2, 2, 3, 1]) | ||
|
||
if __name__ == '__main__': | ||
main() | ||
|