Skip to content

Commit 9530816

Browse files
authored
Inline HeApiTestUtils (#183)
1 parent dde8851 commit 9530816

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

Sources/TestUtilities/HeApiTestUtils.swift

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ public enum HeAPITestHelpers {
149149
}
150150
}
151151

152+
@inlinable
152153
static func encodingTest<Scheme: HeScheme>(
153154
context: Context<Scheme>,
154155
encodeFormat: EncodeFormat,
@@ -212,6 +213,7 @@ public enum HeAPITestHelpers {
212213
}
213214

214215
/// Testing the encoding/decoding functions of the scheme.
216+
@inlinable
215217
public static func schemeEncodeDecodeTest(context: Context<some HeScheme>) throws {
216218
for encodeFormat in EncodeFormat.allCases {
217219
for polyFormat: PolyFormat.Type in [Coeff.self, Eval.self] {
@@ -227,6 +229,7 @@ public enum HeAPITestHelpers {
227229
}
228230

229231
/// Testing the encryption and decryption of the scheme.
232+
@inlinable
230233
public static func schemeEncryptDecryptTest<Scheme: HeScheme>(context: Context<Scheme>) throws {
231234
let testEnv = try TestEnv(context: context, format: .coefficient)
232235
var ciphertext1 = testEnv.ciphertext1
@@ -244,6 +247,7 @@ public enum HeAPITestHelpers {
244247
}
245248

246249
/// Testing zero-ciphertext generation of the scheme.
250+
@inlinable
247251
public static func schemeEncryptZeroDecryptTest<Scheme: HeScheme>(context: Context<Scheme>) throws {
248252
let testEnv = try TestEnv(context: context, format: .coefficient)
249253
let zeros = [Scheme.Scalar](repeating: 0, count: context.degree)
@@ -269,6 +273,7 @@ public enum HeAPITestHelpers {
269273
}
270274

271275
/// Testing addition with zero-ciphertext of the scheme.
276+
@inlinable
272277
public static func schemeEncryptZeroAddDecryptTest<Scheme: HeScheme>(context: Context<Scheme>) throws {
273278
let testEnv = try TestEnv(context: context, format: .coefficient)
274279
let expected = [Scheme.Scalar](repeating: 0, count: context.degree)
@@ -292,6 +297,7 @@ public enum HeAPITestHelpers {
292297
}
293298

294299
/// Testing multiplication with zero-ciphertext of the scheme.
300+
@inlinable
295301
public static func schemeEncryptZeroMultiplyDecryptTest<Scheme: HeScheme>(context: Context<Scheme>) throws {
296302
let testEnv = try TestEnv(context: context, format: .coefficient)
297303
let expected = [Scheme.Scalar](repeating: 0, count: context.degree)
@@ -304,6 +310,7 @@ public enum HeAPITestHelpers {
304310
}
305311

306312
/// Testing ciphertext addition of the scheme.
313+
@inlinable
307314
public static func schemeCiphertextAddTest<Scheme: HeScheme>(context: Context<Scheme>) async throws {
308315
let testEnv = try TestEnv(context: context, format: .coefficient)
309316
let data1 = testEnv.data1
@@ -407,6 +414,7 @@ public enum HeAPITestHelpers {
407414
}
408415

409416
/// Testing ciphertext subtraction of the scheme.
417+
@inlinable
410418
public static func schemeCiphertextSubtractTest<Scheme: HeScheme>(context: Context<Scheme>) async throws {
411419
let testEnv = try TestEnv(context: context, format: .coefficient)
412420
let data1 = testEnv.data1
@@ -511,6 +519,7 @@ public enum HeAPITestHelpers {
511519
}
512520

513521
/// testing ciphertext multiplication of the scheme.
522+
@inlinable
514523
public static func schemeCiphertextCiphertextMultiplyTest<Scheme: HeScheme>(
515524
context: Context<Scheme>) async throws
516525
{
@@ -549,6 +558,7 @@ public enum HeAPITestHelpers {
549558
}
550559

551560
/// Testing CT-PT inner product of the scheme.
561+
@inlinable
552562
public static func schemeCiphertextPlaintextInnerProductTest<Scheme: HeScheme>(
553563
context: Context<Scheme>) async throws
554564
{
@@ -619,6 +629,7 @@ public enum HeAPITestHelpers {
619629
}
620630

621631
/// Testing CT-CT inner product of the scheme.
632+
@inlinable
622633
public static func schemeCiphertextCiphertextInnerProductTest<Scheme: HeScheme>(
623634
context: Context<Scheme>) async throws
624635
{
@@ -672,6 +683,7 @@ public enum HeAPITestHelpers {
672683
}
673684

674685
/// Testing CT-CT multiplication followed by CT-PT addition of the scheme.
686+
@inlinable
675687
public static func schemeCiphertextMultiplyAddPlainTest<Scheme: HeScheme>(context: Context<Scheme>) throws {
676688
guard context.supportsSimdEncoding else {
677689
return
@@ -732,6 +744,7 @@ public enum HeAPITestHelpers {
732744
}
733745

734746
/// Testing CT-PT multiplication followed by CT-PT addition of the scheme.
747+
@inlinable
735748
public static func schemeCiphertextPlaintextMultiplyAddPlainTest<Scheme: HeScheme>(
736749
context: Context<Scheme>) async throws
737750
{
@@ -766,6 +779,7 @@ public enum HeAPITestHelpers {
766779
}
767780

768781
/// Testing CT-PT multiplication followed by CT-PT subtraction of the scheme.
782+
@inlinable
769783
public static func schemeCiphertextPlaintextMultiplySubtractPlainTest<Scheme: HeScheme>(
770784
context: Context<Scheme>) async throws
771785
{
@@ -803,6 +817,7 @@ public enum HeAPITestHelpers {
803817
}
804818

805819
/// Testing CT-CT multiplication followed by CT-CT subtraction of the scheme.
820+
@inlinable
806821
public static func schemeCiphertextMultiplySubtractTest<Scheme: HeScheme>(context: Context<Scheme>) async throws {
807822
guard context.supportsSimdEncoding else {
808823
return
@@ -836,6 +851,7 @@ public enum HeAPITestHelpers {
836851
}
837852

838853
/// Testing ciphertext negation of the scheme.
854+
@inlinable
839855
public static func schemeCiphertextNegateTest<Scheme: HeScheme>(context: Context<Scheme>) async throws {
840856
let testEnv = try TestEnv(context: context, format: .coefficient)
841857
let negatedData = testEnv.data1.map { data1 in
@@ -862,6 +878,7 @@ public enum HeAPITestHelpers {
862878
}
863879

864880
/// Testing CT-PT addition of the scheme.
881+
@inlinable
865882
public static func schemeCiphertextPlaintextAddTest<Scheme: HeScheme>(context: Context<Scheme>) async throws {
866883
guard context.supportsSimdEncoding else {
867884
return
@@ -979,6 +996,7 @@ public enum HeAPITestHelpers {
979996
}
980997

981998
/// Testing CT-PT subtraction of the scheme.
999+
@inlinable
9821000
public static func schemeCiphertextPlaintextSubtractTest<Scheme: HeScheme>(
9831001
context: Context<Scheme>) async throws
9841002
{
@@ -1093,6 +1111,7 @@ public enum HeAPITestHelpers {
10931111
}
10941112

10951113
/// Testing CT-PT multiplication of the scheme.
1114+
@inlinable
10961115
public static func schemeCiphertextPlaintextMultiplyTest<Scheme: HeScheme>(
10971116
context: Context<Scheme>) async throws
10981117
{
@@ -1149,7 +1168,8 @@ public enum HeAPITestHelpers {
11491168
expected: productData)
11501169
}
11511170

1152-
/// Testign ciphertext rotation of the scheme.
1171+
/// Testing ciphertext rotation of the scheme.
1172+
@inlinable
11531173
public static func schemeRotationTest<Scheme: HeScheme>(context: Context<Scheme>) async throws {
11541174
func runRotationTest(context: Context<Scheme>, galoisElements: [Int], multiStep: Bool) async throws {
11551175
let degree = context.degree
@@ -1231,6 +1251,7 @@ public enum HeAPITestHelpers {
12311251
}
12321252

12331253
/// Testing apply Galois element of the scheme.
1254+
@inlinable
12341255
public static func schemeApplyGaloisTest<Scheme: HeScheme>(context: Context<Scheme>) async throws {
12351256
guard context.supportsSimdEncoding, context.supportsEvaluationKey else {
12361257
return
@@ -1270,6 +1291,7 @@ public enum HeAPITestHelpers {
12701291
}
12711292

12721293
/// testing noise budget estimation.
1294+
@inlinable
12731295
public static func noiseBudgetTest<Scheme: HeScheme>(context: Context<Scheme>) throws {
12741296
let testEnv = try TestEnv(context: context, format: .coefficient)
12751297

@@ -1315,7 +1337,8 @@ public enum HeAPITestHelpers {
13151337
}
13161338

13171339
/// testing repeated addition.
1318-
public static func repeatAdditionTest<Scheme: HeScheme>(context: Context<Scheme>) async throws {
1340+
@inlinable
1341+
public static func repeatedAdditionTest<Scheme: HeScheme>(context: Context<Scheme>) async throws {
13191342
let testEnv = try HeAPITestHelpers.TestEnv<Scheme>(context: context, format: .coefficient)
13201343

13211344
var coeffCiphertext = testEnv.ciphertext1
@@ -1339,6 +1362,7 @@ public enum HeAPITestHelpers {
13391362
}
13401363

13411364
/// testing multiply inverse power of x.
1365+
@inlinable
13421366
public static func multiplyInverseTest<Scheme: HeScheme>(context: Context<Scheme>) async throws {
13431367
let testEnv = try HeAPITestHelpers.TestEnv<Scheme>(context: context, format: .coefficient)
13441368

Sources/TestUtilities/TestUtilities.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import Testing
2626
/// - absoluteTolerance: An optional absolute tolerance to enforce.
2727
/// - Returns: true if the expressions are close to each other
2828
extension BinaryFloatingPoint {
29+
@inlinable
2930
package func isClose(to value: Self,
3031
relativeTolerance: Self = Self(1e-5),
3132
absoluteTolerance: Self = Self(1e-8)) -> Bool
@@ -90,6 +91,7 @@ extension [UInt8] {
9091
}
9192
}
9293

94+
@usableFromInline
9395
package enum TestUtils {
9496
/// A polynomial degree suitable for testing.
9597
package static let testPolyDegree = 16
@@ -151,9 +153,8 @@ extension TestUtils {
151153
return Double(binCount) * probabilityOfExactlyCountBallsInFirstBin
152154
}
153155

154-
package static func getRandomPlaintextData<T: ScalarType>(count: Int,
155-
in range: Range<T>) -> [T]
156-
{
156+
@inlinable
157+
package static func getRandomPlaintextData<T: ScalarType>(count: Int, in range: Range<T>) -> [T] {
157158
(0..<count).map { _ in T.random(in: range) }
158159
}
159160

Tests/HomomorphicEncryptionTests/HeAPITests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ struct HeAPITests {
176176
try await HeAPITestHelpers.schemeApplyGaloisTest(context: context)
177177
try bfvTestKeySwitching(context: context)
178178
try HeAPITestHelpers.noiseBudgetTest(context: context)
179-
try await HeAPITestHelpers.repeatAdditionTest(context: context)
179+
try await HeAPITestHelpers.repeatedAdditionTest(context: context)
180180
try await HeAPITestHelpers.multiplyInverseTest(context: context)
181181
}
182182
}

0 commit comments

Comments
 (0)