Skip to content

Commit

Permalink
Test fixes for issue #17
Browse files Browse the repository at this point in the history
New access style.
  • Loading branch information
Rickasaurus committed Oct 19, 2013
1 parent c355edd commit 66c7a1c
Showing 1 changed file with 28 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,30 @@ open FSMatlab.InterfaceTypes

open TestHelpers


open Toolboxes.matlab.elfun
[<Fact>]
let ``function calls with arrays should execute and return a single correct answer`` () =
let res = Toolboxes.matlab.elfun.nthroot([|9.0; 49.0|], 2.0) |> EGT1<double []>
let res = M.nthroot([|9.0; 49.0|], 2.0) |> EGT1<double []>
Assert.Equal<double []>([|3.0; 7.0|], res)

[<Fact>]
let ``function calls that expect a matrix should work correctly`` () =
let res = Toolboxes.matlab.matfun.trace(Array2D.create 5 5 1.0) |> EGT1<double>
Assert.Equal<double>(5.0, res)

[<Fact>]
let ``function calls that return a vector should work correctly`` () =
let testVal = [|0.0; 0.0; 0.0|]
let res = Toolboxes.matlab.elfun.cos(testVal) |> EGT1<double []>
let res = M.cos(testVal) |> EGT1<double []>
Assert.Equal<double []>([|1.0; 1.0; 1.0|], res)

[<Fact>]
let ``function calls that return a matrix should work correctly`` () =
let testVal = Array2D.create 5 5 0.0
let expectedVal = Array2D.create 5 5 1.0
let res = Toolboxes.matlab.elfun.cos(testVal :> obj) |> EGT1<double[,]>
let res = M.cos(testVal :> obj) |> EGT1<double[,]>
Assert.Equal<double [,]>(expectedVal, res)

[<Fact>]
let ``simple function calls should execute and return a single correct answer`` () =
AssertNoVariableChanges (fun _ ->
let appliedHandle = Toolboxes.matlab.elfun.nthroot(9.0, 2.0)
let appliedHandle = M.nthroot(9.0, 2.0)
let resultVarName = "test1_output"
use res_var = appliedHandle.ExecuteNamed([|resultVarName|]).[0] in // You must name the output on the matlab side
let res_untyped = res_var.GetUntyped() :?> double
Expand All @@ -48,7 +45,7 @@ let ``simple function calls should execute and return a single correct answer``
[<Fact>]
let ``simple function calls should execute and return a single correct answer with helpers`` () =
AssertNoVariableChanges (fun _ ->
let res_var = Toolboxes.matlab.elfun.nthroot(9.0, 2.0) |> E1
let res_var = M.nthroot(9.0, 2.0) |> E1
use res_var = res_var in
let res_untyped = res_var.GetUntyped() :?> double
let res_typed : double = res_var.Get()
Expand All @@ -59,7 +56,7 @@ let ``simple function calls should execute and return a single correct answer wi
[<Fact>]
let ``simple function calls should execute and return a single correct answer with execute and retrieve helper`` () =
AssertNoVariableChanges (fun _ ->
let (EG1(res_untyped)) = Toolboxes.matlab.elfun.nthroot(9.0, 2.0)
let (EG1(res_untyped)) = M.nthroot(9.0, 2.0)
Assert.Equal(3.0, res_untyped :?> double)
)

Expand All @@ -68,31 +65,43 @@ let ``simple function calls should work with matlab-side bound variables`` () =
AssertNoVariableChanges (fun _ ->
use nine = Data.UnsafeOverwriteVariable "nine" 9.0
use two = Data.UnsafeOverwriteVariable "two" 2.0
let (EG1(res_untyped)) = Toolboxes.matlab.elfun.nthroot(nine, two)
let (EG1(res_untyped)) = M.nthroot(nine, two)
Assert.Equal(3.0, res_untyped :?> double)
)


open Toolboxes.matlab.matfun
[<Fact>]
let ``function calls that expect a matrix should work correctly`` () =
let res = M.trace(Array2D.create 5 5 1.0) |> EGT1<double>
Assert.Equal<double>(5.0, res)






open Toolboxes.matlab.elmat
[<Fact>]
let ``function with two output params should work correctly with lefthand side execute-get`` () =
AssertNoVariableChanges (fun _ ->
let (EG2(m,n)) = Toolboxes.matlab.elmat.size([|1.0;2.0;3.0;4.0;5.0|])
let (EG2(m,n)) = M.size([|1.0;2.0;3.0;4.0;5.0|])
Assert.Equal(1.0, m :?> double)
Assert.Equal(5.0, n :?> double)
)

[<Fact>]
let ``function with two output params should work correctly with right out execute-get`` () =
AssertNoVariableChanges (fun _ ->
let m,n = Toolboxes.matlab.elmat.size([|1.0;2.0;3.0;4.0;5.0|]) |> EG2
let m,n = M.size([|1.0;2.0;3.0;4.0;5.0|]) |> EG2
Assert.Equal(1.0, m :?> double)
Assert.Equal(5.0, n :?> double)
)

[<Fact>]
let ``function with two output params should work correctly with right out execute-get-typed`` () =
AssertNoVariableChanges (fun _ ->
let m,n = Toolboxes.matlab.elmat.size([|1.0;2.0;3.0;4.0;5.0|]) |> EGT2<double,double>
let m,n = M.size([|1.0;2.0;3.0;4.0;5.0|]) |> EGT2<double,double>
Assert.Equal(1.0, m)
Assert.Equal(5.0, n)
)
Expand All @@ -101,11 +110,12 @@ let ``function with two output params should work correctly with right out execu
let ``error in matlab computation should cause an appropriate exception`` () =
AssertNoVariableChanges (fun _ ->
Assert.Throws<MatlabErrorException>( new Assert.ThrowsDelegate(fun _ ->
Toolboxes.matlab.elfun.nthroot("hello") |> EG1 |> ignore
M.nthroot("hello") |> EG1 |> ignore
)) |> ignore
)


open Toolboxes.matlab.strfun
[<Fact>]
let ``function calls with varargsin should work correctly`` () =
let res = Toolboxes.matlab.strfun.strcat("one", "two", "three") |> EGT1<string>
let res = M.strcat("one", "two", "three") |> EGT1<string>
Assert.Equal<string>("onetwothree", res)

0 comments on commit 66c7a1c

Please sign in to comment.