Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version: 6.1
// swift-tools-version: 6.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
Expand Down
26 changes: 24 additions & 2 deletions Tests/DifferentiationTests/DifferentiationTests.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
import Testing
@testable import Differentiation

@Test func example() async throws {
// Write your test here and use APIs like `#expect(...)` to check expected conditions.
@Suite("Basic Differentiation") struct BasicDifferentiationTests {
@differentiable(reverse)
private func xSquared(x: Double) -> Double {
return x * x
}

private struct Vector2: Differentiable {
var x: Double
var y: Double
}

private func selfDotProduct(of vector: Vector2) -> Double {
return (vector.x * vector.x) + (vector.y * vector.y)
}

@Test func simpleFunctionDerivative() {
#expect(gradient(at: 3, of: xSquared) == 6.0)
}

@Test func simpleStructDerivative() {
let gradientOfDotProduct = gradient(at: Vector2(x: 5.0, y: 5.0), of: selfDotProduct)
#expect(gradientOfDotProduct == Vector2.TangentVector(x: 10.0, y: 10.0))
}

}