Skip to content

Commit d191960

Browse files
committed
Overload <, > for chromosome; Add tests and a prop
- Simple test for chromosome overloaded opperators - Adds a "is pro" bool to chromosome
1 parent 9979f88 commit d191960

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

chromosome.py

100644100755
+18
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1+
#!/usr/bin/env python2
2+
13
class Chromosome:
24
def __init__(self, genes = [], score = 0):
35
self.genes = genes
46
self.score = score
7+
self.is_top_performer = False
8+
9+
def __gt__(self, other):
10+
return self.score > other.score
11+
12+
def __lt__(self, other):
13+
return self.score < other.score
514

615
def append(self, value):
716
self.genes.append(value)
@@ -14,3 +23,12 @@ def __setitem__(self, index, value):
1423

1524
def __len__(self):
1625
return len(self.genes)
26+
27+
28+
if __name__ == "__main__":
29+
c = Chromosome(score = 1)
30+
d = Chromosome(score = 2)
31+
print(c > d)
32+
print(d > c)
33+
print(c < d)
34+
print(d < c)

0 commit comments

Comments
 (0)