+unit PrimeFactors.DUnit.Test;
+ Expected: TArray<Integer>;
+ TPrimeFactorsTest = class(TTestCase)
+ class function FactorsCases: TArray<TPrimeFactor>; static;
+ [TestCaseSource('FactorsCases')]
+ procedure CheckPrimeFactorsTest(const primeFactor: TPrimeFactor);
+ // https://en.wikipedia.org/wiki/Prime_factor
+ FactorsTable: array[0..9] of TPrimeFactor = (
+ (Input: 1; Expected: []),
+ (Input: 2; Expected: [2]),
+ (Input: 3; Expected: [3]),
+ (Input: 4; Expected: [2, 2]),
+ (Input: 5; Expected: [5]),
+ (Input: 6; Expected: [2, 3]),
+ (Input: 7; Expected: [7]),
+ (Input: 8; Expected: [2, 2, 2]),
+ (Input: 9; Expected: [3, 3]),
+ (Input: 2 * 2 * 3 * 3 * 5 * 7 * 11 * 11 * 13; Expected: [2, 2, 3, 3, 5, 7, 11, 11, 13])
+class function TPrimeFactorsTest.FactorsCases: TArray<TPrimeFactor>;
+ Result := TArray.Copy<TPrimeFactor>(FactorsTable);
+procedure TPrimeFactorsTest.CheckPrimeFactorsTest(const primeFactor: TPrimeFactor);
+ CheckEquals(primeFactor.Expected.ToString, TPrime.Factorization(primeFactor.Input).ToString);