Skip to content
Snippets Groups Projects
Select Git revision
  • master
  • rohlfing/update-matplotlib-dependencies
  • jupyterlab-extension-upgrade
  • development
  • v0.1.9-a
  • v0.1.9
  • v0.1.8
  • v0.1.7
  • v0.1.6
  • v0.1.5
  • v0.1.4
  • v0.1.3
  • v0.1.2
  • v0.1.1
  • v0.1.0
15 results

api.rst

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    Tests.fs 58.19 KiB
    module Tests
    
    #if INTERACTIVE
    #load "Interactive.fsx"
    #endif
    
    open NUnit.Framework
    open FsUnit
    open System.Collections.Generic
    open MathNet.Numerics
    open MathNet.Symbolics
    
    open Operators
    
    // Test: x should evaluate to expected
    let inline (-->) x expected = x |> should equal expected
    
    // Test: x should evaluate to the expected string when formatted *nicely*
    let inline (==>) x expected = Infix.format x |> should equal expected
    
    // Test: x should evaluate to the expected string when formatted *strictly* (not denormalized)
    let inline (===>) x expected = Infix.formatStrict x |> should equal expected
    
    // extra test helpers for tuples, list, arrays and hash-sets - maybe there's a better way?
    let inline (==|>) (x1, x2) expected = (Infix.format x1, Infix.format x2) |> should equal expected
    let inline (==||>) (x1, x2, x3) expected = (Infix.format x1, Infix.format x2, Infix.format x3) |> should equal expected
    let inline (==+>) x expected = List.iter2 (fun x e -> Infix.format x |> should equal e) x expected
    let inline (==->) x expected = Array.iter2 (fun x e -> Infix.format x |> should equal e) x expected
    let inline (==*>) (x:HashSet<Expression>) (expected:string list) = HashSet(expected).SetEquals(x |> Seq.map Infix.format) |> should be True
    
    // extra test helper for MathML (just normalizing XML, really)
    let inline (==/>) (x:string) expected = x |> should equal (Xml.normalizeString expected)
    
    // variables
    let x = symbol "x"
    let y = symbol "y"
    let z = symbol "z"
    let a = symbol "a"
    let b = symbol "b"
    let c = symbol "c"
    let d = symbol "d"
    let e = symbol "e"
    let f = symbol "f"
    
    [<Test>]
    let ``Number Expressions`` () =
    
        // equivalent:
        number 3 ==> "3"
        3Q ==> "3"
    
        // expressions are not comparable (NoComparison) to prevent errors,
        // but if the expressions are numbers we can use compareNumber:
        Numbers.compare 0Q 1Q --> -1
        Numbers.compare 1Q 1Q --> 0
        Numbers.compare 1Q 2Q --> -1
        Numbers.compare 0Q (1Q/2Q) --> -1
        Numbers.compare 1Q (1Q/2Q) --> 1
        Numbers.compare (1Q/2Q) 0Q --> 1
        Numbers.compare (1Q/2Q) 1Q --> -1
        Numbers.compare 1Q infinity --> -1
        Numbers.compare 1Q complexInfinity --> -1
        Numbers.compare 1Q negativeInfinity --> 1
        Numbers.compare infinity 1Q --> 1
        Numbers.compare complexInfinity 1Q --> 1
        Numbers.compare negativeInfinity 1Q --> -1
        Numbers.compare negativeInfinity infinity --> -1
        Numbers.compare infinity negativeInfinity --> 1
    
        Numbers.max [ 2Q; 4Q; 7Q/2 ] --> 4Q