-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:boinx/BXSwiftUtils
- Loading branch information
Showing
6 changed files
with
150 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
BXSwiftUtilsTests/Math & Geometry/Comparable+ClipTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// | ||
// Comparable+ClipTests.swift | ||
// BXSwiftUtils-Tests | ||
// | ||
// Created by Stefan Fochler on 22.11.18. | ||
// Copyright © 2018 Boinx Software Ltd. & Imagine GbR. All rights reserved. | ||
// | ||
|
||
import XCTest | ||
import BXSwiftUtils | ||
|
||
class Comparable_ClipTests : XCTestCase | ||
{ | ||
func testClippedMinMax() | ||
{ | ||
XCTAssertEqual(5.0.clipped(min: 0.0, max: 10.0), 5.0) | ||
XCTAssertEqual(5.0.clipped(min: 0.0, max: 5.0), 5.0) | ||
XCTAssertEqual(5.0.clipped(min: 0.0, max: 4.0), 4.0) | ||
XCTAssertEqual(5.0.clipped(min: 6.0, max: 10.0), 6.0) | ||
} | ||
|
||
func testClippedRange() | ||
{ | ||
XCTAssertEqual(5.0.clipped(to: 0...10), 5.0) | ||
XCTAssertEqual(5.0.clipped(to: 0...5), 5.0) | ||
XCTAssertEqual(5.0.clipped(to: 0...4), 4.0) | ||
XCTAssertEqual(5.0.clipped(to: 6...10), 6.0) | ||
} | ||
|
||
func testClipMinMax() | ||
{ | ||
var value = 5.0 | ||
value.clip(min: 2.0, max: 3.0) | ||
XCTAssertEqual(value, 3.0) | ||
} | ||
|
||
func testClipRange() | ||
{ | ||
var value = 5.0 | ||
value.clip(to: 2...3) | ||
XCTAssertEqual(value, 3.0) | ||
} | ||
|
||
func testInvalidMinMax() | ||
{ | ||
XCTAssertThrowsError(try NSException.toSwiftError | ||
{ | ||
let _ = 5.0.clipped(min: 10.0, max: 0) | ||
}) | ||
XCTAssertThrowsError(try NSException.toSwiftError | ||
{ | ||
var value = 5.0 | ||
value.clip(min: 10.0, max: 0) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters