Char by Zed Lopez
Example: * Char
"Char"
Include Char by Zed Lopez.
Include Unit Tests by Zed Lopez.
Use test automatically.
Use quit after autotesting.
Lab is a room.
Ord-text is a unit test. "Ordinal of text".
For testing ord-text:
for "Cat" assert ord of "Cat" is 67;
for "empty" assert ord of "" is 0;
for "B" assert ord of "B" is 66;
Char-for-num is a unit test. "char for <number>".
For testing char-for-num:
for "32 -> space" assert "[char 32]" exactly matches " ";
for "122 -> z" assert "[char 122]" exactly matches "z";
Text-to-char is a unit test. "char of <text>".
For testing text-to-char:
for "space" assert char of " " is char 32;
for "z" assert char of "z" is char 122;
Ord-char is a unit test. "Ordinal of char".
For testing ord-char:
for "C" assert ord of char 67 is 67;
for " " assert ord of char 32 is 32;
Char-list-to-num-list is a unit test. "ord of <list of unicode characters>".
For testing char-list-to-num-list:
let L be a list of unicode characters;
add char 67 to L;
add char 97 to L;
add char 116 to L;
for "Cat" assert ord of L is { 67, 97, 116 };
Num-list-to-char-list is a unit test. "chars of <list of numbers>".
For testing num-list-to-char-list:
let L be chars of { 67, 97, 116 };
for "Cat" assert entry 2 in L is char 97;
for "Cat" assert number of entries in L is 3;
Text-to-chars is a unit test. "chars of <text>".
For testing text-to-chars:
let L be chars of "Cat";
for "Cat, first" assert entry 1 in L is char 67;
for "Cat, last" assert entry 3 in L is char 116;
for "Cat" assert number of entries in L is 3;
Join-char-list is a unit test. "<list of sayable values> joined by <sayable value>".
Numericat is a list of unicode characters that varies.
asterisk is initially "*".
comma-space is initially ", ".
empty-string is initially "".
For testing join-char-list:
now numericat is chars of { 67, 97, 116 };
for "C*a*t" assert "[numericat joined by asterisk]" exactly matches "C*a*t";
for "C, a, t" assert "[numericat joined by comma-space]" exactly matches "C, a, t";
for "saying Cat" assert "[numericat joined by empty-string]" exactly matches "Cat";
Say list of chars as a text is a unit test.
For testing say list of chars as a text:
let L be chars of { 67, 97, 116 };
for "say cat" assert "[L as a text]" exactly matches "Cat";
Joined is a unit test. "Joined"
For testing joined:
let L be chars of { 67, 97, 116 };
for "join L" assert "[L joined]" exactly matches "Cat";
Alice is a person. Bob is a person.
Alice-and-bob is initially { Alice, Bob }.
sv-joined is a unit test. "Sayable value joined."
For testing sv-joined:
for "alicebob" assert "[alice-and-bob joined]" exactly matches "AliceBob".
char-list-as-text is a unit test. "List of chars as a text".
For testing char-list-as-text:
let L be chars of { 67, 97, 116 };
let T be L as a text;
for "char list as text" assert T exactly matches "Cat";
n-copies is a unit test. "N copies".
For testing n-copies:
for "0 copies" assert "[0 copies of char 88]" exactly matches "";
for "3 copies" assert "[3 copies of char 88]" exactly matches "XXX";
n-spaces is a unit test. "N spaces".
For testing n-spaces:
for "5 spaces" assert "[5 spaces]" exactly matches " ";