Skip to content

Commit

Permalink
Merge pull request #19 from stscoundrel/feature/younger-futhark-settings
Browse files Browse the repository at this point in the history
Younger Futhark: add rune style settings & constructors
  • Loading branch information
stscoundrel authored Jun 18, 2022
2 parents b0c29ab + a9e27af commit 048a4d9
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,33 @@
import com.github.stscoundrel.riimut.Transform;

public class YoungerFuthark implements Dialect {
enum Variant {
LONG_BRANCH,
SHORT_TWIG
}

public YoungerFuthark() {
runeStyle = Variant.LONG_BRANCH;
}

public YoungerFuthark(Variant style) {
runeStyle = style;
}

private Variant runeStyle;

private void setVariant(Variant variant) {
runeStyle = variant;
}

public void useLongBranch() {
setVariant(Variant.LONG_BRANCH);
}

public void useShortTwig() {
setVariant(Variant.SHORT_TWIG);
}

static final HashMap<String, String> LETTERS_TO_LONG_BRANCH_RUNES = new HashMap<String, String>() {
{
put("a", "ᛅ");
Expand Down Expand Up @@ -133,6 +160,10 @@ public String lettersToShortTwigRunes(String content) {
}

public String lettersToRunes(String content) {
if (runeStyle == Variant.SHORT_TWIG) {
return Transform.withDictionary(content, LETTERS_TO_SHORT_TWIG_RUNES);
}

return Transform.withDictionary(content, LETTERS_TO_LONG_BRANCH_RUNES);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,45 @@ public void testTransformsRunesToTextContent() {

assertEquals(letters, result);
}

public void testStyleVariantSetters() {
String letters = "aábcdðeéfghiíjklmnoópqrstþuúvwxyýzåäæöøǫþ";
String expectedLongBranchRunes = "ᛅᛅᛒᛋᛏᚦᛁᛁᚠᚴᚼᛁᛁᛁᚴᛚᛘᚾᚢᚢᛒᚴᚱᛋᛏᚦᚢᚢᚢᚢᛋᚢᚢᛋᚢᛅᛅᚢᚢᚢᚦ";
String expectedShortTwigRunes = "ᛆᛆᛒᛌᛐᚦᛁᛁᚠᚴᚽᛁᛁᛁᚴᛚᛘᚿᚢᚢᛒᚴᚱᛌᛐᚦᚢᚢᚢᚢᛌᚢᚢᛌᚢᛆᛆᚢᚢᚢᚦ";

YoungerFuthark youngerFuthark = new YoungerFuthark();

// Expected to use long branch as default.
String longBranchResult = youngerFuthark.lettersToRunes(letters);

// Change to short twig.
youngerFuthark.useShortTwig();
String shortTwigResult = youngerFuthark.lettersToRunes(letters);

// Switch back to long branch
youngerFuthark.useLongBranch();
String secondLongBranchResult = youngerFuthark.lettersToRunes(letters);

assertEquals(expectedLongBranchRunes, longBranchResult);
assertEquals(expectedShortTwigRunes, shortTwigResult);
assertEquals(expectedLongBranchRunes, secondLongBranchResult);
}

public void testConstructorsWithVariantSettings() {
String letters = "aábcdðeéfghiíjklmnoópqrstþuúvwxyýzåäæöøǫþ";
String expectedLongBranchRunes = "ᛅᛅᛒᛋᛏᚦᛁᛁᚠᚴᚼᛁᛁᛁᚴᛚᛘᚾᚢᚢᛒᚴᚱᛋᛏᚦᚢᚢᚢᚢᛋᚢᚢᛋᚢᛅᛅᚢᚢᚢᚦ";
String expectedShortTwigRunes = "ᛆᛆᛒᛌᛐᚦᛁᛁᚠᚴᚽᛁᛁᛁᚴᛚᛘᚿᚢᚢᛒᚴᚱᛌᛐᚦᚢᚢᚢᚢᛌᚢᚢᛌᚢᛆᛆᚢᚢᚢᚦ";

YoungerFuthark youngerFutharkDefault = new YoungerFuthark();
YoungerFuthark youngerFutharkLongBranch = new YoungerFuthark(YoungerFuthark.Variant.LONG_BRANCH);
YoungerFuthark youngerFutharkShortTwig = new YoungerFuthark(YoungerFuthark.Variant.SHORT_TWIG);

String defaultResult = youngerFutharkDefault.lettersToRunes(letters);
String shortTwigResult = youngerFutharkShortTwig.lettersToRunes(letters);
String longBranchResult = youngerFutharkLongBranch.lettersToRunes(letters);

assertEquals(expectedLongBranchRunes, defaultResult);
assertEquals(expectedShortTwigRunes, shortTwigResult);
assertEquals(expectedLongBranchRunes, longBranchResult);
}
}

0 comments on commit 048a4d9

Please sign in to comment.