Skip to content

Commit

Permalink
wasm/two-fer: 2nd iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
vpayno committed Nov 6, 2023
1 parent 014fd9d commit 60d4a30
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 34 deletions.
4 changes: 2 additions & 2 deletions wasm/two-fer/coverage/clover.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<coverage generated="1699240284808" clover="3.2.0">
<project timestamp="1699240284808" name="All files">
<coverage generated="1699243322499" clover="3.2.0">
<project timestamp="1699243322499" name="All files">
<metrics statements="0" coveredstatements="0" conditionals="0" coveredconditionals="0" methods="0" coveredmethods="0" elements="0" coveredelements="0" complexity="0" loc="0" ncloc="0" packages="0" files="0" classes="0"/>
</project>
</coverage>
2 changes: 1 addition & 1 deletion wasm/two-fer/coverage/lcov-report/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ <h1>All files</h1>
<div class='footer quiet pad2 space-top1 center small'>
Code coverage generated by
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
at 2023-11-06T03:11:24.805Z
at 2023-11-06T04:02:02.497Z
</div>
<script src="prettify.js"></script>
<script>
Expand Down
56 changes: 28 additions & 28 deletions wasm/two-fer/run-tests-wasm.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,25 @@ Node versions:

Running: js-beautify ./babel.config.js ./two-fer.spec.js

beautified babel.config.js
beautified two-fer.spec.js
beautified babel.config.js - unchanged
beautified two-fer.spec.js - unchanged

real 0m0.085s
user 0m0.082s
sys 0m0.016s
real 0m0.086s
user 0m0.088s
sys 0m0.010s


==============================================================================

Exit code: 0

real 0m0.387s
user 0m0.380s
sys 0m0.071s
real 0m0.396s
user 0m0.391s
sys 0m0.073s

real 0m0.390s
user 0m0.382s
sys 0m0.072s
real 0m0.399s
user 0m0.394s
sys 0m0.074s

===============================================================================

Expand Down Expand Up @@ -69,49 +69,49 @@ Running: npm run test -- --coverage
> test
> node --experimental-vm-modules node_modules/jest/bin/jest.js ./* --coverage

(node:21586) ExperimentalWarning: VM Modules is an experimental feature. This feature could change at any time
(node:15647) ExperimentalWarning: VM Modules is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
PASS ./two-fer.spec.js
twoFer()
✓ no name given (2 ms)
○ skipped a name given
○ skipped another name given
a name given
another name given (1 ms)

----------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
----------|---------|----------|---------|---------|-------------------
All files | 0 | 0 | 0 | 0 |
----------|---------|----------|---------|---------|-------------------
Test Suites: 1 passed, 1 total
Tests: 2 skipped, 1 passed, 3 total
Tests: 3 passed, 3 total
Snapshots: 0 total
Time: 0.576 s, estimated 1 s
Time: 0.296 s, estimated 1 s
Ran all test suites matching /.\/HELP.md|.\/LICENSE|.\/README.md|.\/babel.config.js|.\/node_modules|.\/package-lock.json|.\/package.json|.\/run-tests-wasm.txt|.\/two-fer.spec.js|.\/two-fer.wat/i.

real 0m1.186s
user 0m1.229s
sys 0m0.140s
real 0m0.932s
user 0m0.958s
sys 0m0.107s


==============================================================================

Exit code: 0

real 0m1.498s
user 0m1.522s
sys 0m0.204s
real 0m1.265s
user 0m1.265s
sys 0m0.168s

real 0m1.501s
user 0m1.522s
sys 0m0.206s
real 0m1.267s
user 0m1.267s
sys 0m0.168s

===============================================================================

Running: misspell ./two-fer.wat

real 0m0.029s
user 0m0.032s
sys 0m0.016s
real 0m0.036s
user 0m0.035s
sys 0m0.014s

===============================================================================

Expand Down
4 changes: 2 additions & 2 deletions wasm/two-fer/two-fer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ describe("twoFer()", () => {
expect(twoFer()).toEqual("One for you, one for me.");
});

xtest("a name given", () => {
test("a name given", () => {
expect(twoFer("Alice")).toEqual("One for Alice, one for me.");
});

xtest("another name given", () => {
test("another name given", () => {
expect(twoFer("Bob")).toEqual("One for Bob, one for me.");
});
});
30 changes: 29 additions & 1 deletion wasm/two-fer/two-fer.wat
Original file line number Diff line number Diff line change
@@ -1,8 +1,36 @@
;; https://exercism.org/tracks/wasm/exercises/two-fer

(module
(memory (export "mem") 1)

;; default return value/string
;; 012345678901234567890123
(data (i32.const 0) "One for you, one for me.")

(func (export "twoFer") (param $offset i32) (param $length i32) (result i32 i32)
(return (i32.const 0) (i32.const 24))
;; return the default string when there input is zero-length
(if (i32.eqz (local.get $length))
(return (i32.const 0) (i32.const 24))
)

;; copy "One for ", offset 24+8=>32
(memory.copy (i32.const 24) (i32.const 0) (i32.const 8))

;; copy input string after "One for ", offset 32+$length
(memory.copy (i32.const 32) (local.get $offset) (local.get $length))

;; copy the end of the default string after the function input
(memory.copy
;; new offset =>32+$length
(i32.add (i32.const 32) (local.get $length))

;; copy ", one for me." to the end off 32+$length
(i32.const 11) (i32.const 13)
)

;; return the new string
(return (i32.const 24)
(i32.add (i32.const 21) (local.get $length))
)
)
)

0 comments on commit 60d4a30

Please sign in to comment.