Try to sort the **cases** using the network, return the number of misses. If **cases** is None, test all possible cases according to the network dimensionality.
(self, cases=None)
| 64 | values[wire1], values[wire2] = values[wire2], values[wire1] |
| 65 | |
| 66 | def assess(self, cases=None): |
| 67 | """Try to sort the **cases** using the network, return the number of |
| 68 | misses. If **cases** is None, test all possible cases according to |
| 69 | the network dimensionality. |
| 70 | """ |
| 71 | if cases is None: |
| 72 | cases = product((0, 1), repeat=self.dimension) |
| 73 | |
| 74 | misses = 0 |
| 75 | ordered = [[0]*(self.dimension-i) + [1]*i for i in range(self.dimension+1)] |
| 76 | for sequence in cases: |
| 77 | sequence = list(sequence) |
| 78 | self.sort(sequence) |
| 79 | misses += (sequence != ordered[sum(sequence)]) |
| 80 | return misses |
| 81 | |
| 82 | def draw(self): |
| 83 | """Return an ASCII representation of the network.""" |
no test coverage detected