Skip to content

Commit

Permalink
Tidy up rotational-cipher
Browse files Browse the repository at this point in the history
- Mark second to last tests xtest
- Remove unnecessary exp import
- Use global constants for "A", "Z", "a" and "z"
- Add instructions.append.md
  • Loading branch information
kahgoh committed Oct 20, 2023
1 parent a79584e commit fec813b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## Reserved Memory

Bytes 64-319 of the linear memory are reserved for the input string.

The input string can be modified in place if desired.
13 changes: 9 additions & 4 deletions exercises/practice/rotational-cipher/.meta/proof.ci.wat
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
(module
(memory (export "mem") 1)

(global $A i32 (i32.const 65))
(global $Z i32 (i32.const 90))
(global $a i32 (i32.const 97))
(global $z i32 (i32.const 122))

(func $wrap (param $low i32) (param $high i32) (param $value i32) (param $shiftKey i32) (result i32)
(local $newValue i32)
(local.set $newValue (local.get $value))
Expand Down Expand Up @@ -63,8 +68,8 @@
;; shift upper case
(local.set $value
(call $wrap
(i32.const 65)
(i32.const 90)
(global.get $A)
(global.get $Z)
(i32.load8_u (local.get $index))
(local.get $shiftKey)
)
Expand All @@ -73,8 +78,8 @@
;; shift lower case
(local.set $value
(call $wrap
(i32.const 97)
(i32.const 122)
(global.get $a)
(global.get $z)
(local.get $value)
(local.get $shiftKey)
)
Expand Down
19 changes: 9 additions & 10 deletions exercises/practice/rotational-cipher/rotational-cipher.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { compileWat, WasmRunner } from "@exercism/wasm-lib";
import exp from "constants";

let wasmModule;
let currentInstance;
Expand Down Expand Up @@ -58,39 +57,39 @@ describe("Rotational Cipher", () => {
expect(rotate("a", 0)).toEqual("a");
});

test("rotate a by 1", () => {
xtest("rotate a by 1", () => {
expect(rotate("a", 1)).toEqual("b");
});

test("rotate a by 26, same output as input", () => {
xtest("rotate a by 26, same output as input", () => {
expect(rotate("a", 26)).toEqual("a");
});

test("rotate m by 13", () => {
xtest("rotate m by 13", () => {
expect(rotate("m", 13)).toEqual("z");
});

test("rotate n by 13 with wrap around alphabet", () => {
xtest("rotate n by 13 with wrap around alphabet", () => {
expect(rotate("n", 13)).toEqual("a");
});

test("rotate capital letters", () => {
xtest("rotate capital letters", () => {
expect(rotate("OMG", 5)).toEqual("TRL");
});

test("rotate spaces", () => {
xtest("rotate spaces", () => {
expect(rotate("O M G", 5)).toEqual("T R L");
});

test("rotate numbers", () => {
xtest("rotate numbers", () => {
expect(rotate("Testing 1 2 3 testing", 4)).toEqual("Xiwxmrk 1 2 3 xiwxmrk");
});

test("rotate punctuation", () => {
xtest("rotate punctuation", () => {
expect(rotate("Let's eat, Grandma!", 21)).toEqual("Gzo'n zvo, Bmviyhv!");
});

test("rotate all letters", () => {
xtest("rotate all letters", () => {
expect(rotate("The quick brown fox jumps over the lazy dog.", 13)).toEqual("Gur dhvpx oebja sbk whzcf bire gur ynml qbt.");
});
});

0 comments on commit fec813b

Please sign in to comment.