-
Notifications
You must be signed in to change notification settings - Fork 10.4k
/
Copy pathderived_conformances.swift
35 lines (30 loc) · 1.14 KB
/
derived_conformances.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
// RUN: %target-run-simple-swift
// REQUIRES: executable_test
import StdlibUnittest
#if os(macOS)
import Darwin.C
#else
import Glibc
#endif
var DerivedConformanceTests = TestSuite("DerivedConformances")
DerivedConformanceTests.test("MemberwiseInitializers") {
struct AllVarStoredPropertiesHaveInitialValue: Differentiable, AdditiveArithmetic {
var x = Float(100)
var y = Float(100)
}
// Verify that `.zero` actually initializes properties to zero.
expectEqual(AllVarStoredPropertiesHaveInitialValue(x: 0, y: 0),
AllVarStoredPropertiesHaveInitialValue.zero)
expectEqual(AllVarStoredPropertiesHaveInitialValue.zero.x, 0)
expectEqual(AllVarStoredPropertiesHaveInitialValue.zero.y, 0)
struct HasNoDerivativeConstant: Differentiable {
@noDerivative let constant1 = Float(1)
@noDerivative let constant2 = Double(1)
var x = Float(1)
}
expectEqual(HasNoDerivativeConstant.AllDifferentiableVariables(x: 0),
HasNoDerivativeConstant.AllDifferentiableVariables.zero)
expectEqual(HasNoDerivativeConstant.CotangentVector(x: 0),
HasNoDerivativeConstant.CotangentVector.zero)
}
runAllTests()