Skip to content

Commit

Permalink
Add test for mod function.
Browse files Browse the repository at this point in the history
  • Loading branch information
bradhowes committed Jun 26, 2024
1 parent 236a92e commit 87d9551
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
21 changes: 15 additions & 6 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-case-paths",
"state" : {
"revision" : "fc45e7b2cfece9dd80b5a45e6469ffe67fe67984",
"version" : "0.14.1"
"revision" : "b871e5ed11a23e52c2896a92ce2c829982ff8619",
"version" : "1.4.2"
}
},
{
Expand All @@ -32,17 +32,26 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-parsing",
"state" : {
"revision" : "27c941bbd22a4bbc53005a15a0440443fd892f70",
"version" : "0.12.1"
"revision" : "a0e7d73f462c1c38c59dc40a3969ac40cea42950",
"version" : "0.13.0"
}
},
{
"identity" : "swift-syntax",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-syntax",
"state" : {
"revision" : "303e5c5c36d6a558407d364878df131c3546fad8",
"version" : "510.0.2"
}
},
{
"identity" : "xctest-dynamic-overlay",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/xctest-dynamic-overlay",
"state" : {
"revision" : "4af50b38daf0037cfbab15514a241224c3f62f98",
"version" : "0.8.5"
"revision" : "6f30bdba373bbd7fbfe241dddd732651f2fbd1e2",
"version" : "1.1.2"
}
}
],
Expand Down
23 changes: 23 additions & 0 deletions Tests/MathParserTests/MathParserTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -668,4 +668,27 @@ error: unexpected input
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)
}

func testMod() {
XCTAssertEqual(5.truncatingRemainder(dividingBy: 3), parser.parse("mod(5, 3)")?.value)
XCTAssertEqual(3.truncatingRemainder(dividingBy: 5), parser.parse("mod(3, 5)")?.value)
XCTAssertEqual(55.truncatingRemainder(dividingBy: 3), parser.parse("mod(55, 3)")?.value)
XCTAssertEqual(35.truncatingRemainder(dividingBy: 5), parser.parse("mod(35, 5)")?.value)

XCTAssertEqual(-2, parser.parse("mod(-5, 3)")?.value)
XCTAssertEqual(-3, parser.parse("mod(-3, 5)")?.value)
XCTAssertEqual(-1, parser.parse("mod(-55, 3)")?.value)
XCTAssertEqual(0, parser.parse("mod(-35, 5)")?.value)

XCTAssertEqual(2, parser.parse("mod(5, -3)")?.value)
XCTAssertEqual(3, parser.parse("mod(3, -5)")?.value)
XCTAssertEqual(1, parser.parse("mod(55, -3)")?.value)
XCTAssertEqual(0, parser.parse("mod(35, -5)")?.value)

XCTAssertEqual(-2, parser.parse("mod(-5, -3)")?.value)
XCTAssertEqual(-3, parser.parse("mod(-3, -5)")?.value)
XCTAssertEqual(-1, parser.parse("mod(-55, -3)")?.value)
XCTAssertEqual(0, parser.parse("mod(-35, -5)")?.value)
}
}

0 comments on commit 87d9551

Please sign in to comment.