From d78c9768a06bedbf3dd433389d59a1999e6d2344 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Thu, 9 Apr 2015 17:44:44 -0700 Subject: 1044 --- cpp/032string.mu | 88 -------------------------------------------------------- cpp/040string.mu | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 88 deletions(-) delete mode 100644 cpp/032string.mu create mode 100644 cpp/040string.mu diff --git a/cpp/032string.mu b/cpp/032string.mu deleted file mode 100644 index 17608e5f..00000000 --- a/cpp/032string.mu +++ /dev/null @@ -1,88 +0,0 @@ -recipe string-equal [ - default-space:address:space <- new location:type, 30:literal - a:address:array:character <- next-ingredient - a-len:integer <- length a:address:array:character/deref - b:address:array:character <- next-ingredient - b-len:integer <- length b:address:array:character/deref - # compare lengths - { - length-equal?:boolean <- equal a-len:integer, b-len:integer - break-if length-equal?:boolean - reply 0:literal - } - # compare each corresponding character - i:integer <- copy 0:literal - { - done?:boolean <- greater-or-equal i:integer, a-len:integer - break-if done?:boolean - a2:character <- index a:address:array:character/deref, i:integer - b2:character <- index b:address:array:character/deref, i:integer - { - chars-match?:boolean <- equal a2:character, b2:character - break-if chars-match?:boolean - reply 0:literal - } - i:integer <- add i:integer, 1:literal - loop - } - reply 1:literal -] - -scenario string-equal-reflexive [ - run [ - default-space:address:space <- new location:type, 30:literal - x:address:array:character <- new [abc] - 3:boolean/raw <- string-equal x:address:array:character, x:address:array:character - ] - memory should contain [ - 3 <- 1 # x == x for all x - ] -] - -scenario string-equal-identical [ - run [ - default-space:address:space <- new location:type, 30:literal - x:address:array:character <- new [abc] - y:address:array:character <- new [abc] - 3:boolean/raw <- string-equal x:address:array:character, y:address:array:character - ] - memory should contain [ - 3 <- 1 # abc == abc - ] -] - -scenario string-equal-distinct-lengths [ - run [ - default-space:address:space <- new location:type, 30:literal - x:address:array:character <- new [abc] - y:address:array:character <- new [abcd] - 3:boolean/raw <- string-equal x:address:array:character, y:address:array:character - ] - memory should contain [ - 3 <- 0 # abc != abcd - ] -] - -scenario string-equal-with-empty [ - run [ - default-space:address:space <- new location:type, 30:literal - x:address:array:character <- new [] - y:address:array:character <- new [abcd] - 3:boolean/raw <- string-equal x:address:array:character, y:address:array:character - ] - memory should contain [ - 3 <- 0 # "" != abcd - ] -] - -scenario string-equal-common-lengths-but-distinct [ - run [ - default-space:address:space <- new location:type, 30:literal - x:address:array:character <- new [abc] - y:address:array:character <- new [abd] - 3:boolean/raw <- string-equal x:address:array:character, y:address:array:character - ] - memory should contain [ - 3 <- 0 # abc != abd - ] -] diff --git a/cpp/040string.mu b/cpp/040string.mu new file mode 100644 index 00000000..17608e5f --- /dev/null +++ b/cpp/040string.mu @@ -0,0 +1,88 @@ +recipe string-equal [ + default-space:address:space <- new location:type, 30:literal + a:address:array:character <- next-ingredient + a-len:integer <- length a:address:array:character/deref + b:address:array:character <- next-ingredient + b-len:integer <- length b:address:array:character/deref + # compare lengths + { + length-equal?:boolean <- equal a-len:integer, b-len:integer + break-if length-equal?:boolean + reply 0:literal + } + # compare each corresponding character + i:integer <- copy 0:literal + { + done?:boolean <- greater-or-equal i:integer, a-len:integer + break-if done?:boolean + a2:character <- index a:address:array:character/deref, i:integer + b2:character <- index b:address:array:character/deref, i:integer + { + chars-match?:boolean <- equal a2:character, b2:character + break-if chars-match?:boolean + reply 0:literal + } + i:integer <- add i:integer, 1:literal + loop + } + reply 1:literal +] + +scenario string-equal-reflexive [ + run [ + default-space:address:space <- new location:type, 30:literal + x:address:array:character <- new [abc] + 3:boolean/raw <- string-equal x:address:array:character, x:address:array:character + ] + memory should contain [ + 3 <- 1 # x == x for all x + ] +] + +scenario string-equal-identical [ + run [ + default-space:address:space <- new location:type, 30:literal + x:address:array:character <- new [abc] + y:address:array:character <- new [abc] + 3:boolean/raw <- string-equal x:address:array:character, y:address:array:character + ] + memory should contain [ + 3 <- 1 # abc == abc + ] +] + +scenario string-equal-distinct-lengths [ + run [ + default-space:address:space <- new location:type, 30:literal + x:address:array:character <- new [abc] + y:address:array:character <- new [abcd] + 3:boolean/raw <- string-equal x:address:array:character, y:address:array:character + ] + memory should contain [ + 3 <- 0 # abc != abcd + ] +] + +scenario string-equal-with-empty [ + run [ + default-space:address:space <- new location:type, 30:literal + x:address:array:character <- new [] + y:address:array:character <- new [abcd] + 3:boolean/raw <- string-equal x:address:array:character, y:address:array:character + ] + memory should contain [ + 3 <- 0 # "" != abcd + ] +] + +scenario string-equal-common-lengths-but-distinct [ + run [ + default-space:address:space <- new location:type, 30:literal + x:address:array:character <- new [abc] + y:address:array:character <- new [abd] + 3:boolean/raw <- string-equal x:address:array:character, y:address:array:character + ] + memory should contain [ + 3 <- 0 # abc != abd + ] +] -- cgit 1.4.1-2-gfad0