on master help sign in
Merge pull request #670 from urbit/ford-fix
f6866d4rmariani
tutorials/hoon/ford.md+6−6
@@ -100,7 +100,7 @@ Now that we have covered the distinctive features of Ford, we now dive into some
100#### Vase
100#### Vase
101
101
102From `hoon.hoon`:
102From `hoon.hoon`:
103−```
103+```hoon
104+$ vase [p=type q=*]
104+$ vase [p=type q=*]
105```
105```
106A `vase` is simply typed data, and it is used wherever typed data is being explicitly worked with.
106A `vase` is simply typed data, and it is used wherever typed data is being explicitly worked with.
@@ -135,7 +135,7 @@ The `/+` rune accepts a filename as an argument. It interprets that filename as
135
135
136To run this example, put this code in your desk at `gen/faslus.hoon` and run `+faslus` in your dojo.
136To run this example, put this code in your desk at `gen/faslus.hoon` and run `+faslus` in your dojo.
137
137
138−```
138+```hoon
139/+ time-to-id
139/+ time-to-id
140::
140::
141:- %say
141:- %say
@@ -150,7 +150,7 @@ You can import multiple libraries with a single `/+` rune by separating them wit
150
150
151Replace the code in `gen/faslus.hoon` with the following:
151Replace the code in `gen/faslus.hoon` with the following:
152
152
153−```
153+```hoon
154/+ time-to-id, hep-to-cab
154/+ time-to-id, hep-to-cab
155::
155::
156:- %say
156:- %say
@@ -167,7 +167,7 @@ Another feature of the `/+` rune (and `/-` below) is the ability to specify the
167
167
168Example:
168Example:
169
169
170−```
170+```hoon
171/+ time-to-id, hep-to-cab/4/~zod
171/+ time-to-id, hep-to-cab/4/~zod
172```
172```
173will load the `hep-to-cab` library from `~zod` at `%clay` revision `4`.
173will load the `hep-to-cab` library from `~zod` at `%clay` revision `4`.
@@ -178,7 +178,7 @@ The `/-` rune accepts a filename as an argument. It interprets that filename as
178
178
179Example:
179Example:
180
180
181−```
181+```hoon
182/- talk
182/- talk
183::
183::
184*serial:talk
184*serial:talk
@@ -194,4 +194,4 @@ Ford is the vane utilized for unit testing, which are the the simplest sort of t
194
194
195One typically tests software by feeding it inputs and seeing if the outputs matches what is expected (something that is determined manually by the engineer). Unit tests work with only a single "module" at a time. What exactly is meant by this is shown by example in the following walkthrough, but for now it suffices to say that unit tests are in contrast with larger scale tests variously known as end-to-end tests, system tests, and integration tests.
195One typically tests software by feeding it inputs and seeing if the outputs matches what is expected (something that is determined manually by the engineer). Unit tests work with only a single "module" at a time. What exactly is meant by this is shown by example in the following walkthrough, but for now it suffices to say that unit tests are in contrast with larger scale tests variously known as end-to-end tests, system tests, and integration tests.
196
196
197−### [Next up: Unit Testing with Ford](../ford.md)
197+### [Next up: Unit Testing with Ford](../test-sets.md)
tutorials/hoon/test-sets.md+10−10
@@ -34,7 +34,7 @@ OK /sys/hoon/set/test-set-wyt
34```
34```
35Here, we ran a generator called `+test` with a path argument `/sys/hoon/set`. The output tells us that all tests ran successfully. Running this generator automatically appends `/tests/` to the front of the path entered, so lets look at the beginning of `/tests/sys/hoon/set.hoon` to see what the `+test` generator took as an input:
35Here, we ran a generator called `+test` with a path argument `/sys/hoon/set`. The output tells us that all tests ran successfully. Running this generator automatically appends `/tests/` to the front of the path entered, so lets look at the beginning of `/tests/sys/hoon/set.hoon` to see what the `+test` generator took as an input:
36
36
37−```
37+```hoon
38:: Tests for +in (set logic)
38:: Tests for +in (set logic)
39::
39::
40/+ *test
40/+ *test
@@ -46,7 +46,7 @@ Here, we ran a generator called `+test` with a path argument `/sys/hoon/set`. Th
46We note that the first line that isn't a comment is `/+ *test`, which from [the previous lesson](../ford.md) you know means that we are importing the shared library `lib/test.hoon`. This is followed by a core which will contain arms that perform our tests, which we will see an example of shortly.
46We note that the first line that isn't a comment is `/+ *test`, which from [the previous lesson](../ford.md) you know means that we are importing the shared library `lib/test.hoon`. This is followed by a core which will contain arms that perform our tests, which we will see an example of shortly.
47
47
48In `lib/test.hoon`, we find a core with a few gates: `expect-eq`, `expect-fail`, and `category`. The source for `expect-eq` is:
48In `lib/test.hoon`, we find a core with a few gates: `expect-eq`, `expect-fail`, and `category`. The source for `expect-eq` is:
49−```
49+```hoon
50++ expect-eq
50++ expect-eq
51 |= [expected=vase actual=vase]
51 |= [expected=vase actual=vase]
52 ^- tang
52 ^- tang
@@ -75,7 +75,7 @@ This is the most frequently used gate in testing, so we may conclude that any te
75## Testing the functionality of set intersection
75## Testing the functionality of set intersection
76
76
77Here's one of the testing arms in the set testing core:
77Here's one of the testing arms in the set testing core:
78−```
78+```hoon
79++ test-set-int ^- tang
79++ test-set-int ^- tang
80 =/ s-nul=(set @) *(set @)
80 =/ s-nul=(set @) *(set @)
81 =/ s-asc=(set @) (sy (gulf 1 7))
81 =/ s-asc=(set @) (sy (gulf 1 7))
@@ -109,7 +109,7 @@ Here's one of the testing arms in the set testing core:
109 ==
109 ==
110```
110```
111This arm is used to test whether the set intersection functionality works as expected. Let's walk through it line by line.
111This arm is used to test whether the set intersection functionality works as expected. Let's walk through it line by line.
112−```
112+```hoon
113++ test-set-int ^- tang
113++ test-set-int ^- tang
114 =/ s-nul=(set @) *(set @)
114 =/ s-nul=(set @) *(set @)
115 =/ s-asc=(set @) (sy (gulf 1 7))
115 =/ s-asc=(set @) (sy (gulf 1 7))
@@ -118,11 +118,11 @@ This arm is used to test whether the set intersection functionality works as exp
118 =/ s-dup (sy ~[1 1 4 1 3 5 9 4])
118 =/ s-dup (sy ~[1 1 4 1 3 5 9 4])
119```
119```
120We see that this arm returns a `tang`, i.e. a pretty-printed message, and adds several sets to the subject which will be utilized in our tests.
120We see that this arm returns a `tang`, i.e. a pretty-printed message, and adds several sets to the subject which will be utilized in our tests.
121−```
121+```hoon
122;: weld
122;: weld
123```
123```
124`;: weld` calls `weld`, which is typically a binary function, as an n-ary function. This will allow us to concatenate all of `tang`s that are to be generated into a single `tang`.
124`;: weld` calls `weld`, which is typically a binary function, as an n-ary function. This will allow us to concatenate all of `tang`s that are to be generated into a single `tang`.
125−```
125+```hoon
126 :: Checks with empty set
126 :: Checks with empty set
127 ::
127 ::
128 %+ expect-eq
128 %+ expect-eq
@@ -130,7 +130,7 @@ We see that this arm returns a `tang`, i.e. a pretty-printed message, and adds s
130 !> (~(int in s-nul) s-asc)
130 !> (~(int in s-nul) s-asc)
131```
131```
132`%+` is used to call a gate with a cell sample. `expect-eq` is the gate, `!> ~` is the head of the sample, and `!> (~(int in s-nul) s-asc)` is the tail of the sample. `!>` is a rune used to wrap a noun in its type - in other words, it produces a `vase`. We've seen this rune before when we learned about the type spear `-:!>`. Thus, what this block of code is doing is checking whether the expected `vase` that is the product of `!> ~` is equal to the `vase` that is the product of `!> (~(int in s-nul) s-asc)`. `s-nul` is simply the empty set, and here we are taking the intersection of the empty set with `s-asc`, a non-empty set. This ought to produce the empty set of course, and so when this block of code runs, we compare the expected result `!> ~` (which is something we determined by hand) with the actual result `!> (~(int in s-nul) s-asc)`.
132`%+` is used to call a gate with a cell sample. `expect-eq` is the gate, `!> ~` is the head of the sample, and `!> (~(int in s-nul) s-asc)` is the tail of the sample. `!>` is a rune used to wrap a noun in its type - in other words, it produces a `vase`. We've seen this rune before when we learned about the type spear `-:!>`. Thus, what this block of code is doing is checking whether the expected `vase` that is the product of `!> ~` is equal to the `vase` that is the product of `!> (~(int in s-nul) s-asc)`. `s-nul` is simply the empty set, and here we are taking the intersection of the empty set with `s-asc`, a non-empty set. This ought to produce the empty set of course, and so when this block of code runs, we compare the expected result `!> ~` (which is something we determined by hand) with the actual result `!> (~(int in s-nul) s-asc)`.
133−```
133+```hoon
134 %+ expect-eq
134 %+ expect-eq
135 !> ~
135 !> ~
136 !> (~(int in s-asc) s-nul)
136 !> (~(int in s-asc) s-nul)
@@ -138,7 +138,7 @@ We see that this arm returns a `tang`, i.e. a pretty-printed message, and adds s
138This is another test to check if intersection works with the empty set, but we have swapped where `s-asc` and `s-nul` are. We do not know a priori whether this ordering matters (and of course it shouldn't), which is why it is important to perform both tests.
138This is another test to check if intersection works with the empty set, but we have swapped where `s-asc` and `s-nul` are. We do not know a priori whether this ordering matters (and of course it shouldn't), which is why it is important to perform both tests.
139
139
140
140
141−```
141+```hoon
142 :: Checks with all elements different
142 :: Checks with all elements different
143 ::
143 ::
144 %+ expect-eq
144 %+ expect-eq
@@ -147,7 +147,7 @@ This is another test to check if intersection works with the empty set, but we h
147```
147```
148Now we are checking if intersection works correctly when two non-empty sets share no common elements. We expect the intersection to be empty, so our expected `vase` is `!> ~`, and we then compare it with what the set library produces when it takes the intersection of `s-dos` and `s-asc`.
148Now we are checking if intersection works correctly when two non-empty sets share no common elements. We expect the intersection to be empty, so our expected `vase` is `!> ~`, and we then compare it with what the set library produces when it takes the intersection of `s-dos` and `s-asc`.
149
149
150−```
150+```hoon
151 :: Checks success (total intersection)
151 :: Checks success (total intersection)
152 ::
152 ::
153 %+ expect-eq
153 %+ expect-eq
@@ -156,7 +156,7 @@ Now we are checking if intersection works correctly when two non-empty sets shar
156```
156```
157`s-asc` and `s-des` both ought to be the set containing the integers 1 through 7, but `s-asc` was generated with the list `~[1,2,3,4,5,6,7]` while `s-des` was generated with the list `~[7,6,5,4,3,2,1]`. Sets have no ordering, so they ought to be the same. Thus, when we take their intersection, we should get the same set back. So, our expected `vase` is `!> s-asc` and our actual `vase` is `!> (~(int in s-asc) s-des)`.
157`s-asc` and `s-des` both ought to be the set containing the integers 1 through 7, but `s-asc` was generated with the list `~[1,2,3,4,5,6,7]` while `s-des` was generated with the list `~[7,6,5,4,3,2,1]`. Sets have no ordering, so they ought to be the same. Thus, when we take their intersection, we should get the same set back. So, our expected `vase` is `!> s-asc` and our actual `vase` is `!> (~(int in s-asc) s-des)`.
158
158
159−```
159+```hoon
160 :: Checks success (partial intersection)
160 :: Checks success (partial intersection)
161 ::
161 ::
162 %+ expect-eq
162 %+ expect-eq