Skip to content

Commit

Permalink
Convert int to float to prepare for decimal functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
wyze committed Apr 5, 2017
1 parent e808cfc commit 7458b78
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 105 deletions.
54 changes: 27 additions & 27 deletions __tests__/reductive/operation_test.re
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@ let _ =

describe "operation" (fun _ => {
test "create will create a model" (fun _ => {
let { left, right, symbol, total }: Operation.model = Operation.create "2" "2" Action.Add 4;
let { left, right, symbol, total }: Operation.model = Operation.create "2" "2" Action.Add 4.0;
let actual = ( left, right, symbol, total );
let expected = ( "2", "2", Action.Add, 4 );
let expected = ( "2", "2", Action.Add, 4.0 );

expect actual |> toEqual expected;
});

test "default returns empty model" (fun _ => {
let { left, right, symbol, total }: Operation.model = Operation.default;
let actual = ( left, right, symbol, total );
let expected = ( "", "", Action.Pending, 0 );
let expected = ( "", "", Action.Pending, 0.0 );

expect actual |> toEqual expected;
});

test "createEquals returns equal record" (fun _ => {
let model = Operation.create "2" "2" Action.Add 4;
let model = Operation.create "2" "2" Action.Add 4.0;
let { left, right, symbol, total }: Operation.model = Operation.createEquals model;
let actual = ( left, right, symbol, total );
let expected = ( "4", "4", Action.Equals, 4 );
let expected = ( "4", "4", Action.Equals, 4.0 );

expect actual |> toEqual expected;
});
Expand All @@ -37,36 +37,36 @@ describe "operation" (fun _ => {
});

test "execute performs the infix operation" (fun _ => {
let actual = Operation.execute (+) "4" "4";
let expected = 8;
let actual = Operation.execute (+.) "4" "4";
let expected = 8.0;

expect actual |> toEqual expected;
});

test "head returns first item in the list" (fun _ => {
let { left, right, symbol, total }: Operation.model = Operation.head [
Operation.create "1" "" Action.Pending 0,
Operation.create "2" "" Action.Pending 0,
Operation.create "3" "" Action.Pending 0,
Operation.create "4" "" Action.Pending 0,
Operation.create "1" "" Action.Pending 0.0,
Operation.create "2" "" Action.Pending 0.0,
Operation.create "3" "" Action.Pending 0.0,
Operation.create "4" "" Action.Pending 0.0,
];
let actual = ( left, right, symbol, total );
let expected = ( "1", "", Action.Pending, 0 );
let expected = ( "1", "", Action.Pending, 0.0 );

expect actual |> toEqual expected;
});

test "find returns first item matching the predicate" (fun _ => {
let lst = [
Operation.create "4" "" Action.Pending 0,
Operation.create "3" "" Action.Add 0,
Operation.create "2" "" Action.Pending 0,
Operation.create "1" "" Action.Add 0,
Operation.create "4" "" Action.Pending 0.0,
Operation.create "3" "" Action.Add 0.0,
Operation.create "2" "" Action.Pending 0.0,
Operation.create "1" "" Action.Add 0.0,
];
let { left, right, symbol, total }: Operation.model =
Operation.find lst (fun { symbol } => Pervasives.(symbol == Action.Add));
let actual = ( left, right, symbol, total );
let expected = ( "3", "", Action.Add, 0 );
let expected = ( "3", "", Action.Add, 0.0 );

expect actual |> toEqual expected;
});
Expand All @@ -75,25 +75,25 @@ describe "operation" (fun _ => {
let { left, right, symbol, total }: Operation.model =
Operation.default |> Operation.update "3";
let actual = ( left, right, symbol, total );
let expected = ( "3", "", Action.Pending, 3 );
let expected = ( "3", "", Action.Pending, 3.0 );

expect actual |> toEqual expected;
});

test "update handles Add action properly" (fun _ => {
let { left, right, symbol, total }: Operation.model =
Operation.create "3" "" Action.Add 3 |> Operation.update "3";
Operation.create "3" "" Action.Add 3.0 |> Operation.update "3";
let actual = ( left, right, symbol, total );
let expected = ( "3", "3", Action.Add, 6 );
let expected = ( "3", "3", Action.Add, 6.0 );

expect actual |> toEqual expected;
});

test "update handles Multiply action properly" (fun _ => {
let { left, right, symbol, total }: Operation.model =
Operation.create "3" "" Action.Multiply 3 |> Operation.update "3";
Operation.create "3" "" Action.Multiply 3.0 |> Operation.update "3";
let actual = ( left, right, symbol, total );
let expected = ( "3", "3", Action.Multiply, 9 );
let expected = ( "3", "3", Action.Multiply, 9.0 );

expect actual |> toEqual expected;
});
Expand All @@ -107,7 +107,7 @@ describe "operation" (fun _ => {

test "getInput returns proper value for simple list" (fun _ => {
let actual = [
Operation.create "5" "" Action.Pending 5,
Operation.create "5" "" Action.Pending 5.0,
] |> Operation.getInput;
let expected = "5";

Expand All @@ -116,10 +116,10 @@ describe "operation" (fun _ => {

test "getInput returns proper value for complex list" (fun _ => {
let actual = [
Operation.create "14" "14" Action.Equals 14,
Operation.create "7" "2" Action.Multiply 14,
Operation.create "3" "4" Action.Add 7,
Operation.create "1" "2" Action.Add 3,
Operation.create "14" "14" Action.Equals 14.0,
Operation.create "7" "2" Action.Multiply 14.0,
Operation.create "3" "4" Action.Add 7.0,
Operation.create "1" "2" Action.Add 3.0,
] |> Operation.getInput;
let expected = "14";

Expand Down
Loading

0 comments on commit 7458b78

Please sign in to comment.