Title: Tests any ZZ dimension must pass
Ly version: 0.1
Show title: +
Easy tags: +
Tangler: test.util.TestTangler
-- Introduction --
XXX MOCKUP: This code is not actually used at the moment! Ly needs a lot
of work before it can weave & tangle this. The intent is that the code
in here is run as a |unittest| class, while the woven HTML is put
into the |doc/| directory.
This document contains unit tests that any implementation of the |Dim|
interface must pass. It is not assumed that the |Dim| implementation
supports write access (changing connections).
|.test| files for specific dimension implementations must set the following
variables:
- |dim|
- The |Dim| object to test.
- |cells|
- A sequence of cells, connected along |dim| in a nontrivial structure.
The structure should contain ringranks as well as normal
(non-looping) ranks.
-- Note for reading this document --
Note that in Python, objects which do not specify any other behavior
are treated as logically _true_, whereas |None|, the Python
object equivalent to Java's |null|, is treated as logically _false_.
This means that you can simply write |c| in the place of
|c != None|, as in the following code:
if c:
# This code is executed if c is a Cell
else:
# This code is executed if c is None
Respectively, you can use |not c| instead of |c == None|.
Therefore, when testing whether a cell has a connection in a specific
direction, we generally use |if c.s(dim)| instead of |if c.s(dim) != None|.
-- Test that stepping forwards and back gets us back --
for c in cells:
First invariant: stepping zero steps must return the cell
we started from.
assert c.s(dim) == c
Second invariant: If we step n cells in some
direction, stepping n cells in the other
direction must get us back where we started (except
when we stepped over the end of a rank).
for n in range(-10, 10):
if not c.s(dim, n): continue
assert c.s(dim, n).s(dim, -n) == c
-- Test assumptions about headcells and ringranks --
For each cell, we examine its headcell (|c.h(dim)|) and tailcell
(|c.h(dim, 1)|) on our dimension.
for c in cells:
head = c.h(dim)
tail = c.h(dim, 1)
First invariant:
assert tail.h(dim) == head
assert head.h(dim, 1) == tail
Second invariant: On ranks that are not ringranks, the headcell
and the tailcell are the ends of the rank.
if not head.s(dim, -1):
assert not head.s(dim, -1)
assert not tail.s(dim, 1)
Third invariant: On ringranks, the tailcell must be connected
to the headcell.
else:
assert tail.s(dim) == head
assert head.s(dim, -1) == tail
-- Test iterators --
XXX There are no unit tests for dim iterators at the moment.