-
Notifications
You must be signed in to change notification settings - Fork 2
/
basic_functionsTestsInt.swift
48 lines (45 loc) · 1.4 KB
/
basic_functionsTestsInt.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//
// Created by Daniel Strobusch on 2019-05-11.
//
import XCTest
@testable import NdArray
// swiftlint:disable:next type_name
class basic_functionsTestsInt: XCTestCase {
func testAbs() {
// 0d
do {
let a = NdArray<Int>.zeros([])
XCTAssertEqual(abs(a).shape, [])
}
// 2d effective 0d
do {
let a = NdArray<Int>.zeros([1, 0])
XCTAssertEqual(abs(a).shape, [1, 0])
}
// 1d contiguous
do {
let a = NdArray<Int>.range(from: -3, to: 3)
XCTAssertEqual(abs(a).dataArray, a.dataArray.map(abs))
}
// 1d not aligned
do {
let a = NdArray<Int>.range(from: -3, to: 3)[[0... ~ 2]]
XCTAssertEqual(abs(a).dataArray, [3, 1, 1])
}
// 2d C contiguous
do {
let a = NdArray<Int>.range(from: -3, to: 3).reshaped([2, 3], order: .C)
XCTAssertEqual(abs(a).dataArray, [3, 2, 1, 0, 1, 2])
}
// 2d F contiguous
do {
let a = NdArray<Int>.range(from: -3, to: 3).reshaped([2, 3], order: .F)
XCTAssertEqual(abs(a).dataArray, [3, 2, 1, 0, 1, 2])
}
// 2d not aligned
do {
let a = NdArray<Int>.range(from: -5, to: 4 * 3 - 5).reshaped([4, 3], order: .C)[[1... ~ 2]]
XCTAssertEqual(abs(a).dataArray, [2, 1, 0, 4, 5, 6])
}
}
}