-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create testing code for the Nock and Noun module
We test: 1. Nock 2. Noun 3. Noun.Format further we write some custom hoon functions that compile to nock using our standard library, making sure that nock evaluation works as expected. The Noun tests mainly test inserting and indexing
- Loading branch information
Showing
4 changed files
with
114 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
:: Load anoma.hoon into your environemnt as anoma | ||
:: then write .* name [0 2] to get the arm | ||
=use-dec => anoma | ||
|= a=@ud | ||
(dec a) | ||
|
||
=fib => anoma | ||
|= n=@ud | ||
=+ [b=1 a=0] | ||
|- | ||
?: =(n 0) a | ||
%= $ | ||
a b | ||
b (add a b) | ||
n (dec n) | ||
== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
defmodule AnomaTest.Nock do | ||
use ExUnit.Case, async: true | ||
|
||
import Nock | ||
import Noun | ||
|
||
doctest(Nock) | ||
|
||
def using_dec_core() do | ||
arm = Noun.Format.parse_always("[8 [9 342 0 7] 9 2 10 [6 0 14] 0 2]") | ||
sample = 999 | ||
[arm, sample | stdlib_core()] | ||
end | ||
|
||
def factorial() do | ||
arm = Noun.Format.parse_always(" | ||
[ 8 | ||
[1 1 0] | ||
8 | ||
[ 1 | ||
6 | ||
[5 [0 30] 1 0] | ||
[0 13] | ||
9 | ||
2 | ||
10 | ||
[30 8 [9 342 0 31] 9 2 10 [6 0 62] 0 2] | ||
10 | ||
[6 [8 [9 20 0 31] 9 2 10 [6 [0 29] 0 28] 0 2] 0 12] | ||
0 | ||
1 | ||
] | ||
9 | ||
2 | ||
0 | ||
1 | ||
]") | ||
sample = 1 | ||
[arm, sample | stdlib_core()] | ||
end | ||
|
||
describe "Basic functionality" do | ||
test "base call" do | ||
assert nock(using_dec_core(), [9, 2, 0 | 1]) == {:ok, 998} | ||
end | ||
|
||
test "call with changing arguments" do | ||
assert nock(using_dec_core(), [9, 2, 10, [6, 1 | 5], 0 | 1]) == {:ok, 4} | ||
end | ||
end | ||
|
||
describe "Standard Library" do | ||
test "calling fib" do | ||
assert nock(factorial, [9, 2, 10, [6, 1 | 7], 0 | 1]) == {:ok, 13} | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
defmodule AnomaTest.Noun do | ||
use ExUnit.Case, async: true | ||
|
||
import Noun | ||
alias Noun.Format | ||
|
||
doctest(Noun) | ||
doctest(Noun.Format) | ||
|
||
@testing_noun Noun.Format.parse_always("[[4 5] [12 13] 7]") | ||
def testing_noun() do | ||
@testing_noun | ||
end | ||
|
||
test "parse sensible terms" do | ||
assert {:ok, [1 | 2]} = Noun.Format.parse("[1 2]") | ||
assert {:ok, [1, [3 | 5] | 2]} = Noun.Format.parse("[1 [[3 5] 2]]") | ||
end | ||
|
||
test "don't parse incorrect terms" do | ||
assert :error = Noun.Format.parse("[[[[1]]]]") | ||
assert :error = Noun.Format.parse("[[[[") | ||
assert :error = Noun.Format.parse("]]]]") | ||
end | ||
|
||
test "indexing" do | ||
assert axis(1, testing_noun()) == {:ok, testing_noun()} | ||
assert axis(2, testing_noun()) == {:ok, [4 | 5]} | ||
assert axis(6, testing_noun()) == {:ok, [12 | 13]} | ||
assert axis(7, testing_noun()) == {:ok, 7} | ||
assert axis(4, testing_noun()) == {:ok, 4} | ||
assert axis(5, testing_noun()) == {:ok, 5} | ||
assert axis(12, testing_noun()) == {:ok, 12} | ||
assert axis(13, testing_noun()) == {:ok, 13} | ||
end | ||
|
||
test "inserting" do | ||
assert {:ok, term} = replace(2, 2, testing_noun()) | ||
assert axis(2, term) == {:ok, 2} | ||
end | ||
end |