Skip to content

Commit 0c05039

Browse files
committed
cleanup sample lib, remove unused imports and obvious warnings.
Signed-off-by: KtorZ <[email protected]>
1 parent a20b509 commit 0c05039

File tree

1 file changed

+99
-81
lines changed

1 file changed

+99
-81
lines changed

lib/aiken/sample.ak

+99-81
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
use aiken/builtin
2-
use cardano/assets.{Value}
3-
use aiken/interval.{Interval}
4-
use cardano/script_context.{ScriptContext}
5-
use cardano/transaction.{Input, Output, ScriptPurpose, Transaction}
6-
use aiken/crypto.{Blake2b_224, Hash}
7-
use cardano/address.{Address, Credential, Inline, VerificationKey}
82
use aiken/collection/dict
3+
use aiken/crypto
94

105
/// A growth pattern determines how complexity scales with input size
116
pub type Growth {
@@ -24,25 +19,28 @@ fn rand(prng: PRNG) -> Option<(PRNG, Int)> {
2419
when prng is {
2520
Seeded { seed, choices } -> {
2621
let choice = builtin.index_bytearray(seed, 0)
27-
Some((
28-
Seeded {
29-
seed: crypto.blake2b_256(seed),
30-
choices: builtin.cons_bytearray(choice, choices),
31-
},
32-
choice,
33-
))
22+
Some(
23+
(
24+
Seeded {
25+
seed: crypto.blake2b_256(seed),
26+
choices: builtin.cons_bytearray(choice, choices),
27+
},
28+
choice,
29+
),
30+
)
3431
}
35-
Replayed { cursor, choices } -> {
32+
Replayed { cursor, choices } ->
3633
if cursor >= 1 {
3734
let cursor = cursor - 1
38-
Some((
39-
Replayed { cursor, choices },
40-
builtin.index_bytearray(choices, cursor),
41-
))
35+
Some(
36+
(
37+
Replayed { cursor, choices },
38+
builtin.index_bytearray(choices, cursor),
39+
),
40+
)
4241
} else {
4342
None
4443
}
45-
}
4644
}
4745
}
4846

@@ -51,7 +49,7 @@ pub fn apply_growth(pattern: Growth, n: Int) -> Int {
5149
when pattern is {
5250
Constant -> 1
5351
Linear(base) -> base * n
54-
Exponential(base) ->
52+
Exponential(base) ->
5553
if n <= 0 {
5654
0
5755
} else {
@@ -68,11 +66,11 @@ pub fn apply_growth(pattern: Growth, n: Int) -> Int {
6866

6967
// TODO: Probably need to use a builtin in the future.
7068
fn exp_int_helper(base: Int, n: Int, acc: Int) -> Int {
71-
if base <= 0 {
72-
acc
73-
} else {
74-
exp_int_helper(base - 1, n, acc * n)
75-
}
69+
if base <= 0 {
70+
acc
71+
} else {
72+
exp_int_helper(base - 1, n, acc * n)
73+
}
7674
}
7775

7876
// TODO: Probably need to use a builtin in the future.
@@ -110,22 +108,32 @@ pub fn bytestring(growth: Growth) -> Sampler<ByteArray> {
110108
let length_fuzzer = int(growth)(n)
111109
fn(prng) {
112110
when length_fuzzer(prng) is {
113-
Some((prng2, len)) -> {
114-
todo
115-
}
111+
Some((_prng2, _len)) -> todo
116112
None -> None
117113
}
118114
}
119115
}
120116
}
121117

122-
fn list_handler(items_so_far: List<a>, i: Int, scaled_length: Int, fuzzer: Fuzzer<a>, prng: PRNG) -> Option<(PRNG, List<a>)> {
118+
fn list_handler(
119+
items_so_far: List<a>,
120+
i: Int,
121+
scaled_length: Int,
122+
fuzzer: Fuzzer<a>,
123+
prng: PRNG,
124+
) -> Option<(PRNG, List<a>)> {
123125
if i > scaled_length {
124126
Some((prng, items_so_far))
125127
} else {
126128
when fuzzer(prng) is {
127-
Some((new_prng, item)) ->
128-
list_handler([item, ..items_so_far], i + 1, scaled_length, fuzzer, new_prng)
129+
Some((new_prng, item)) ->
130+
list_handler(
131+
[item, ..items_so_far],
132+
i + 1,
133+
scaled_length,
134+
fuzzer,
135+
new_prng,
136+
)
129137
None -> None
130138
}
131139
}
@@ -136,49 +144,56 @@ pub fn list(element_sampler: Sampler<a>, growth: Growth) -> Sampler<List<a>> {
136144
fn(n) {
137145
let scaled_length = apply_growth(growth, n)
138146
let element_fuzzer = element_sampler(n)
139-
fn(prng) {
140-
list_handler([], 0, scaled_length, element_fuzzer, prng)
141-
}
147+
fn(prng) { list_handler([], 0, scaled_length, element_fuzzer, prng) }
142148
}
143149
}
144150

145-
pub fn pair(first_sampler: Sampler<a>, second_sampler: Sampler<b>) -> Sampler<Pair<a, b>> {
146-
fn(n) {
147-
let first_fuzzer = first_sampler(n)
148-
let second_fuzzer = second_sampler(n)
149-
fn(prng) {
150-
when first_fuzzer(prng) is {
151-
Some((prng2, first_val)) -> {
152-
when second_fuzzer(prng2) is {
153-
Some((prng3, second_val)) ->
154-
Some((prng3, Pair(first_val, second_val)))
155-
None -> None
156-
}
157-
}
158-
None -> None
159-
}
160-
}
151+
pub fn pair(
152+
first_sampler: Sampler<a>,
153+
second_sampler: Sampler<b>,
154+
) -> Sampler<Pair<a, b>> {
155+
fn(n) {
156+
let first_fuzzer = first_sampler(n)
157+
let second_fuzzer = second_sampler(n)
158+
fn(prng) {
159+
when first_fuzzer(prng) is {
160+
Some((prng2, first_val)) ->
161+
when second_fuzzer(prng2) is {
162+
Some((prng3, second_val)) ->
163+
Some((prng3, Pair(first_val, second_val)))
164+
None -> None
165+
}
166+
None -> None
167+
}
161168
}
169+
}
162170
}
163171

164-
pub fn pairs(first_sampler: Sampler<a>, second_sampler: Sampler<b>, growth: Growth) {
165-
fn (n) {
166-
let scaled_length = apply_growth(growth, n)
167-
let pair_sampler = pair(first_sampler, second_sampler)(n)
172+
pub fn pairs(
173+
first_sampler: Sampler<a>,
174+
second_sampler: Sampler<b>,
175+
growth: Growth,
176+
) {
177+
fn(n) {
178+
let scaled_length = apply_growth(growth, n)
179+
let pair_sampler = pair(first_sampler, second_sampler)(n)
168180

169-
fn(prng) {
170-
list_handler([], 0, scaled_length, pair_sampler, prng)
171-
}
172-
}
181+
fn(prng) { list_handler([], 0, scaled_length, pair_sampler, prng) }
182+
}
173183
}
174184

175-
pub fn dict(key_sampler: Sampler<ByteArray>, value_sampler: Sampler<a>, growth: Growth) {
176-
fn (n) {
177-
let scaled_length = apply_growth(growth, n)
178-
map(pairs(key_sampler, value_sampler, growth), fn(pairs) {
179-
dict.from_pairs(pairs)
180-
})
181-
}
185+
pub fn dict(
186+
key_sampler: Sampler<ByteArray>,
187+
value_sampler: Sampler<a>,
188+
growth: Growth,
189+
) {
190+
fn(n) {
191+
let _scaled_length = apply_growth(growth, n)
192+
map(
193+
pairs(key_sampler, value_sampler, growth),
194+
fn(pairs) { dict.from_pairs(pairs) },
195+
)
196+
}
182197
}
183198

184199
pub fn map(sampler: Sampler<a>, f: fn(a) -> b) -> Sampler<b> {
@@ -193,20 +208,23 @@ pub fn map(sampler: Sampler<a>, f: fn(a) -> b) -> Sampler<b> {
193208
}
194209
}
195210

196-
pub fn map2(sampler: Sampler<a>, sampler2: Sampler<b>, f: fn(a, b) -> c) -> Sampler<c> {
197-
fn(n) {
198-
let fuzzer1 = sampler(n)
199-
let fuzzer2 = sampler2(n)
200-
fn(prng) {
201-
when fuzzer1(prng) is {
202-
Some((prng2, a)) -> {
203-
when fuzzer2(prng2) is {
204-
Some((prng3, b)) -> Some((prng3, f(a, b)))
205-
None -> None
206-
}
207-
}
208-
None -> None
209-
}
210-
}
211+
pub fn map2(
212+
sampler: Sampler<a>,
213+
sampler2: Sampler<b>,
214+
f: fn(a, b) -> c,
215+
) -> Sampler<c> {
216+
fn(n) {
217+
let fuzzer1 = sampler(n)
218+
let fuzzer2 = sampler2(n)
219+
fn(prng) {
220+
when fuzzer1(prng) is {
221+
Some((prng2, a)) ->
222+
when fuzzer2(prng2) is {
223+
Some((prng3, b)) -> Some((prng3, f(a, b)))
224+
None -> None
225+
}
226+
None -> None
227+
}
211228
}
212-
}
229+
}
230+
}

0 commit comments

Comments
 (0)