-
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.
Merge pull request #4 from smitterl/add_2_wise
Add 2 wise
- Loading branch information
Showing
4 changed files
with
144 additions
and
11 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
File renamed without changes.
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,64 @@ | ||
SEP = "." | ||
|
||
def parts(line): | ||
p = line.split(SEP) | ||
return p | ||
|
||
def pairwise_covered(candidates, line_parts): | ||
for i in range(len(line_parts) - 1): | ||
for j in range(i + 1, len(line_parts)): | ||
cand_i_j = [x for x in candidates if | ||
x[i] == line_parts[i] and | ||
x[j] == line_parts[j]] | ||
if not cand_i_j: | ||
return False | ||
return True | ||
|
||
def pairwise(lines): | ||
diag = [] | ||
|
||
for line in lines: | ||
|
||
line_parts = parts(line) | ||
if line_parts in diag: | ||
continue | ||
|
||
candidates = [x for x in diag if len(x) == len(line_parts)] | ||
if not (candidates and | ||
pairwise_covered(candidates, line_parts)): | ||
diag.append(line_parts) | ||
continue | ||
|
||
return [".".join(x) for x in diag] | ||
|
||
|
||
import unittest | ||
|
||
test_lines = [ | ||
"a1.b1.c1", | ||
"a1.b1.c2", | ||
"a1.b2.c1", | ||
"a1.b2.c2", | ||
"a2.b1.c1", | ||
"a2.b1.c2", | ||
"a2.b2.c1", | ||
"a2.b2.c2", | ||
"a1.d1" | ||
] | ||
|
||
class TestDiagonal(unittest.TestCase): | ||
|
||
def test_pairwise(self): | ||
pairwised = pairwise(test_lines) | ||
self.assertEqual(pairwised, [ | ||
"a1.b1.c1", | ||
"a1.b1.c2", | ||
"a1.b2.c1", | ||
"a1.b2.c2", | ||
"a2.b1.c1", | ||
"a2.b1.c2", | ||
"a2.b2.c1", | ||
"a1.d1"]) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |