Skip to content
Snippets Groups Projects
Select Git revision
  • r0.18
  • master default protected
  • gh-pages
  • alternative-valuetype
  • visual
  • v0.24.0
  • v0.23.0
  • v0.22.0
  • v0.21.0
  • v0.20.0
  • v0.19.0
  • v0.18.1
  • v0.18.0
  • v0.17.0
  • v0.16.0
  • v0.15.0
  • v0.14.0
  • v0.13.0
  • v0.12.0
  • v0.11.0
  • v0.10.1
  • v0.10.0
  • v0.9.0
  • v0.8.0
  • v0.7.1
25 results

Tests.fs

Blame
  • Forked from Severin Delhey / MathNET Symbolics
    Source project has a limited visibility.
    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