Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/k02_numerical_types.jsligo
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const substract_int_and_nat = (n1:int,n2:nat) : int =>
export const substract_nat = (n1:nat,n2:nat) : int =>
K.todo("Should substract two naturals");

export const substract_tez = (n1:tez,n2:tez) : tez =>
export const substract_tez = (n1:tez,n2:tez) : option<tez> =>
K.todo("Should substract two tez values");

/*
Expand Down
2 changes: 1 addition & 1 deletion lib/k04_bytes_type.jsligo
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#import "common/todo.jsligo" "K"

/*
Bytes can be concatenated using the + operator.
Bytes can be concatenated using a built-in function Bytes.concat.
*/

export const concat = (n1:bytes,n2:bytes) : bytes =>
Expand Down
4 changes: 2 additions & 2 deletions lib/k08_record_types.jsligo
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type account_data = {
transactions: nat
};

export let account = () : account_data => {
export const account = () : account_data => {
K.todo("Should return an account data with a balance of 5 tez and 3 transactions");
};

Expand All @@ -30,7 +30,7 @@ const balance : tez = (account()).balance;
Reference; https://ligolang.org/docs/language-basics/maps-records#functional-updates
*/

export contents modify_account = (account: account_data) : account_data => {
export const modify_account = (account: account_data) : account_data => {
K.todo("Should return an account data with 5 transactions");
}

Expand Down
2 changes: 1 addition & 1 deletion solution/k04_bytes_type.jsligo
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#import "common/todo.jsligo" "K"

/*
Bytes can be concatenated using the + operator.
Bytes can be concatenated using a built-in function Bytes.concat.
*/

export const concat = (n1:bytes,n2:bytes) : bytes =>
Expand Down
6 changes: 3 additions & 3 deletions solution/k05_conditional.jsligo
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ const b: bool = false;
*/

const compare_string = (s1:string,s2:string): bool => {
(s1 == s2);
return (s1 == s2);
// K.todo("Should compare two strings");
};

const boolean_and = (b1:bool,b2:bool): bool => {
(b1 && b2);
return (b1 && b2);
// K.todo("Should return the boolean and of b1, b2 ");
};

const boolean_or = (b1:bool,b2:bool): bool => {
(b1 || b2);
return (b1 || b2);
// K.todo("Should return the boolean or of b1, b2");
};

Expand Down
12 changes: 6 additions & 6 deletions test/common/check.jsligo
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ const to_red = (s:string) : string => red + s + reset;

type error<a> = | ["ERROR", {received:a} ];

const equal : <T>((a:T, b:T) => bool) = p => {
Bytes.pack(p[0]) == Bytes.pack(p[1]);
const equal = <T>(a:T, b:T): bool => {
return Bytes.pack(a) == Bytes.pack(b);
};

const status = (b:bool) : string => {
Expand All @@ -20,13 +20,13 @@ const status = (b:bool) : string => {
}
};

const assert_equal : <T>((result:T, expected:T) => unit) = p => {
const result = equal(p[0], p[1]);
const assert_equal = <T>(answer:T, expected:T): unit => {
const result = equal(answer, expected);

Test.println(status(result) + " expected: " + Test.to_string(p[1]));
Test.println(status(result) + " expected: " + Test.to_string(expected));

if (result == false) {
Test.println(" received: " + Test.to_string(p[0]));
Test.println(" received: " + Test.to_string(answer));
};
};

Expand Down
2 changes: 1 addition & 1 deletion test/k03.jsligo
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#import "common/check.jsligo" "Check"
#import "../lib/k03_string_type.jsligo" "Koan"

const case01 = ():unit => Check.assert_equal(Koan.concat(["Hello", " World!"]), "Hello World!");
const case01 = ():unit => Check.assert_equal(Koan.concat("Hello", " World!"), "Hello World!");
const case02 = ():unit => Check.assert_equal(Koan.first("Hello"), "H");
const case03 = ():unit => Check.assert_equal(Koan.length("Hello"), 5 as nat);

Expand Down
2 changes: 1 addition & 1 deletion test/k04.jsligo
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#import "common/check.jsligo" "Check"
#import "../lib/k04_bytes_type.jsligo" "Koan"

const case01 = ():unit => Check.assert_equal(Koan.concat([0x1234, 0x5678]), 0x12345678);
const case01 = ():unit => Check.assert_equal(Koan.concat(0x1234, 0x5678), 0x12345678);
const case02 = ():unit => Check.assert_equal(Koan.first(0x1224), 0x12);
const case03 = ():unit => Check.assert_equal(Koan.length(0x123456), 3 as nat);

Expand Down
26 changes: 13 additions & 13 deletions test/k05.jsligo
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
#import "common/check.jsligo" "Check"
#import "../lib/k05_conditional.jsligo" "Koan"

const case01 = ():unit => Check.assert_equal(Koan.compare_string(["a","a"]), true);
const case02 = ():unit => Check.assert_equal(Koan.compare_string(["a","b"]), false);
const case01 = ():unit => Check.assert_equal(Koan.compare_string("a","a"), true);
const case02 = ():unit => Check.assert_equal(Koan.compare_string("a","b"), false);

const case03 = ():unit => Check.assert_equal(Koan.boolean_and([true,true]), true);
const case04 = ():unit => Check.assert_equal(Koan.boolean_and([true,false]), false);
const case05 = ():unit => Check.assert_equal(Koan.boolean_and([false,true]), false);
const case06 = ():unit => Check.assert_equal(Koan.boolean_and([false,false]), false);
const case03 = ():unit => Check.assert_equal(Koan.boolean_and(true,true), true);
const case04 = ():unit => Check.assert_equal(Koan.boolean_and(true,false), false);
const case05 = ():unit => Check.assert_equal(Koan.boolean_and(false,true), false);
const case06 = ():unit => Check.assert_equal(Koan.boolean_and(false,false), false);

const case07 = ():unit => Check.assert_equal(Koan.boolean_or([true,true]), true);
const case08 = ():unit => Check.assert_equal(Koan.boolean_or([true,false]), true);
const case09 = ():unit => Check.assert_equal(Koan.boolean_or([false,true]), true);
const case10 = ():unit => Check.assert_equal(Koan.boolean_or([false,false]), false);
const case07 = ():unit => Check.assert_equal(Koan.boolean_or(true,true), true);
const case08 = ():unit => Check.assert_equal(Koan.boolean_or(true,false), true);
const case09 = ():unit => Check.assert_equal(Koan.boolean_or(false,true), true);
const case10 = ():unit => Check.assert_equal(Koan.boolean_or(false,false), false);

const case11 = ():unit => Check.assert_equal(Koan.selection([1,2]), "i1 < i2");
const case12 = ():unit => Check.assert_equal(Koan.selection([2,2]), "i1 = i2");
const case13 = ():unit => Check.assert_equal(Koan.selection([2,1]), "i1 > i2");
const case11 = ():unit => Check.assert_equal(Koan.selection(1,2), "i1 < i2");
const case12 = ():unit => Check.assert_equal(Koan.selection(2,2), "i1 = i2");
const case13 = ():unit => Check.assert_equal(Koan.selection(2,1), "i1 > i2");

const test = Check.cases(list([
case01, case02, case03, case04, case05, case06, case07,
Expand Down