Skip to content

Commit

Permalink
Additional tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
bradhowes committed Sep 14, 2023
1 parent 32ca401 commit dbb5e04
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Tests/MathParserTests/MathParserTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,14 @@ final class MathParserTests: XCTestCase {
let parser = MathParser(enableImpliedMultiplication: true)
let token = parser.parse("2+5")
XCTAssertEqual(7, token?.eval())
let token2 = parser.parse("t+4")
XCTAssertEqual(7, token2?.eval("t", value: 3))
}

func testEval() {
let parser = MathParser(enableImpliedMultiplication: false)
let token = parser.parse("t+4")
XCTAssertEqual(7, token?.eval("t", value: 3))
}

func testBuggyImpliedMultiplication() {
Expand Down Expand Up @@ -648,4 +656,16 @@ error: unexpected input
XCTAssertEqual(2 * pow(3, 4) * 5, parser.parse("2 * 3 ^ 4 * 5")?.value)
XCTAssertEqual(2 * pow(3, pow(4, 5)), parser.parse("2 * 3 ^ 4 ^ 5")?.value)
}

func testDegTrig() {
var unaryFunctions = MathParser.defaultUnaryFunctions
unaryFunctions["sin"] = { sin($0 * Double.pi / 180.0) }
unaryFunctions["cos"] = { cos($0 * Double.pi / 180.0) }
var binaryFunctions = MathParser.defaultBinaryFunctions
binaryFunctions["atan2"] = { atan2($0, $1) * 180.0 / Double.pi }
let parser = MathParser(unaryFunctionDict: unaryFunctions, binaryFunctionDict: binaryFunctions)
XCTAssertEqual(sin(Double.pi / 6), parser.parse("sin(30)")?.value)
XCTAssertEqual(cos(Double.pi / 3), parser.parse("cos(60)")?.value)
XCTAssertEqual(atan2(1.0, 1.0) * 180.0 / Double.pi, parser.parse("atan2(1.0, 1.0)")?.value)
}
}

0 comments on commit dbb5e04

Please sign in to comment.