7/21/2019 Prime Factors Kata (1)
1/37
Prime Factors Kata
Object Mentor, Inc.
fitnesse.org
Copyright 2005 by Object Mentor, Inc
All copies must retain this page unchanged.
www.junit.org
www.objectmentor.com
blog.objectmentor.com
7/21/2019 Prime Factors Kata (1)
2/37
Generating Prime Factors.
Although quite short, this kata is fascinating in the wa it shows how !if" statements
become !while" statements as the number of test cases increase. It"s also a
won#erful e$am%le of how algorithms sometimes become sim%ler as the become
more general.
I stumble# u%on this little kata one e&ening when m son was in 'thgra#e. (e
ha# just #isco&ere# that all numbers can be broken #own into a %ro#uct of %rimes
an# was intereste# in e$%loring this further. )o I wrote a little rub %rogram, test*
first, an# was stunne# b how the algorithm e&ol&e#.
I ha&e #one this %articular kata in +a&a .-. his shoul# gi&e ou a feel for the
%ower an# con&enience of some of the new features.
7/21/2019 Prime Factors Kata (1)
3/37
he /equirements.
0 g e n e r a t e 1 n 2 i n t 3
P r i m e F a c t o r s
4 5rite a class name# 6PrimeFactors7 that
has one static metho#2 generate.8 he generate metho# takes an integer
argument an# returns a 9ist:Integer;. hat
list contains the %rime factors in numerical
sequence.
7/21/2019 Prime Factors Kata (1)
4/37
7/21/2019 Prime Factors Kata (1)
5/37
he first test.package primeFactors;
import junit.framework.TestCase;
public class PrimeFactorsTest extends TestCase {
public void testne!" t#rows $xception {
assert$%uals!list!"&PrimeFactors.generate!'"";
}
}
7/21/2019 Prime Factors Kata (1)
6/37
he first test.package primeFactors;
import junit.framework.TestCase;
import java.util.(ist;
public class PrimeFactorsTest extends TestCase {
public void testne!" t#rows $xception {
assert$%uals!list!"&PrimeFactors.generate!'"";
}
private (ist)*nteger+ list!" {
return null;
}}
7/21/2019 Prime Factors Kata (1)
7/37
he first test.package primeFactors;
import junit.framework.TestCase;
import java.util.(ist;
public class PrimeFactorsTest extends TestCase {
public void testne!" t#rows $xception {
assert$%uals!list!"&PrimeFactors.generate!'"";
}
private (ist)*nteger+ list!" {
return null;
}}
package primeFactors;
public class PrimeFactors {
}
7/21/2019 Prime Factors Kata (1)
8/37
he first test.package primeFactors;
import junit.framework.TestCase;
import java.util.(ist;
public class PrimeFactorsTest extends TestCase {
public void testne!" t#rows $xception {
assert$%uals!list!"&PrimeFactors.generate!'"";
}
private (ist)*nteger+ list!" {
return null;
}}
package primeFactors;
import java.util.,;
public class PrimeFactors {
public static (ist)*nteger+ generate!int n" {
return new -rra(ist)*nteger+!";
}
}
expected: but was:
7/21/2019 Prime Factors Kata (1)
9/37
he first test.package primeFactors;
import junit.framework.TestCase;
import java.util.,;
public class PrimeFactorsTest extends TestCase {
public void testne!" t#rows $xception {
assert$%uals!list!"&PrimeFactors.generate!'"";
}
private (ist)*nteger+ list!" {
return new -rra(ist)*nteger+!";
}}
package primeFactors;
import java.util.,;
public class PrimeFactors {
public static (ist)*nteger+ generate!int n" {
return new -rra(ist)*nteger+!";
}
}
7/21/2019 Prime Factors Kata (1)
10/37
he first test.package primeFactors;
import junit.framework.TestCase;
import java.util.,;
public class PrimeFactorsTest extends TestCase {
private (ist)*nteger+ list!" {
return new -rra(ist)*nteger+!";
}
public void testne!" t#rows $xception {
assert$%uals!list!"&PrimeFactors.generate!'"";
}}
package primeFactors;
import java.util.,;
public class PrimeFactors {
public static (ist)*nteger+ generate!int n" {
return new -rra(ist)*nteger+!";
}
}
7/21/2019 Prime Factors Kata (1)
11/37
he )econ# est
7/21/2019 Prime Factors Kata (1)
12/37
he )econ# test.package primeFactors;
import junit.framework.TestCase;
import java.util.,;
public class PrimeFactorsTest extends TestCase {
private (ist)*nteger+ list!" {
return new -rra(ist)*nteger+!";
}
public void testne!" t#rows $xception {
assert$%uals!list!"&PrimeFactors.generate!'"";
}
public void testTwo!" t#rows $xception {
assert$%uals!list!/"&PrimeFactors.generate!/"";
}
}
package primeFactors;
import java.util.,;
public class PrimeFactors {
public static (ist)*nteger+ generate!int n" {
return new -rra(ist)*nteger+!";
}
}
7/21/2019 Prime Factors Kata (1)
13/37
he )econ# test.package primeFactors;
import junit.framework.TestCase;
import java.util.,;
public class PrimeFactorsTest extends TestCase {
private (ist)*nteger+ list!int... ints" {
(ist)*nteger+ list 0new -rra(ist)*nteger+!";
for !int i 1 ints"
list.add!i";
return list;
}
public void testne!" t#rows $xception {
assert$%uals!list!"&PrimeFactors.generate!'"";
}
public void testTwo!" t#rows $xception {
assert$%uals!list!/"&PrimeFactors.generate!/"";
}
}
package primeFactors;
import java.util.,;
public class PrimeFactors {
public static (ist)*nteger+ generate!int n" {
return new -rra(ist)*nteger+!";
}
}
varargs
expected: but was:
7/21/2019 Prime Factors Kata (1)
14/37
he )econ# test.package primeFactors;
import junit.framework.TestCase;
import java.util.,;
public class PrimeFactorsTest extends TestCase {
private (ist)*nteger+ list!int... ints" {
(ist)*nteger+ list 0 new -rra(ist)*nteger+!";
for !int i 1 ints"
list.add!i";
return list;
}
public void testne!" t#rows $xception {
assert$%uals!list!"&PrimeFactors.generate!'"";
}
public void testTwo!" t#rows $xception {
assert$%uals!list!/"&PrimeFactors.generate!/"";
}
}
package primeFactors;
import java.util.,;
public class PrimeFactors {
public static (ist)*nteger+ generate!int n" {
(ist)*nteger+ primes 0 new -rra(ist)*nteger+!";
if !n + '" {
primes.add!/";
}
return primes;
}
}
7/21/2019 Prime Factors Kata (1)
15/37
he )econ# test.package primeFactors;
import static primeFactors.PrimeFactors.generate;
import junit.framework.TestCase;
import java.util.,;
public class PrimeFactorsTest extends TestCase {
private (ist)*nteger+ list!int... ints" {
(ist)*nteger+ list 0 new -rra(ist)*nteger+!";
for !int i 1 ints"
list.add!i";
return list;
}
public void testne!" t#rows $xception {
assert$%uals!list!"&generate!'"";
}
public void testTwo!" t#rows $xception {
assert$%uals!list!/"&generate!/"";
}
}
package primeFactors;
import java.util.,;
public class PrimeFactors {
public static (ist)*nteger+ generate!int n" {
(ist)*nteger+ primes 0 new -rra(ist)*nteger+!";
if !n + '" {
primes.add!/";
}
return primes;
}
}
7/21/2019 Prime Factors Kata (1)
16/37
he hir# est
7/21/2019 Prime Factors Kata (1)
17/37
he hir# test.package primeFactors;
import static primeFactors.PrimeFactors.generate;
import junit.framework.TestCase;
import java.util.,;
public class PrimeFactorsTest extends TestCase {
private (ist)*nteger+ list!int... ints" {
(ist)*nteger+ list 0 new -rra(ist)*nteger+!";
for !int i 1 ints"
list.add!i";
return list;
}
public void testne!" t#rows $xception {
assert$%uals!list!"&generate!'"";
}
public void testTwo!" t#rows $xception {
assert$%uals!list!/"&generate!/"";
}
public void testT#ree!" t#rows $xception {
assert$%uals!list!2"&generate!2"";
}
}
package primeFactors;
import java.util.,;
public class PrimeFactors {
public static (ist)*nteger+ generate!int n" {
(ist)*nteger+ primes 0 new -rra(ist)*nteger+!";
if !n + '" {
primes.add!/";
}
return primes;
}
}
expected: but was:
7/21/2019 Prime Factors Kata (1)
18/37
he hir# test.package primeFactors;
import static primeFactors.PrimeFactors.generate;
import junit.framework.TestCase;
import java.util.,;
public class PrimeFactorsTest extends TestCase {
private (ist)*nteger+ list!int... ints" {
(ist)*nteger+ list 0 new -rra(ist)*nteger+!";
for !int i 1 ints"
list.add!i";
return list;
}
public void testne!" t#rows $xception {
assert$%uals!list!"&generate!'"";
}
public void testTwo!" t#rows $xception {
assert$%uals!list!/"&generate!/"";
}
public void testT#ree!" t#rows $xception {
assert$%uals!list!2"&generate!2"";
}
}
package primeFactors;
import java.util.,;
public class PrimeFactors {
public static (ist)*nteger+ generate!int n" {
(ist)*nteger+ primes 0 new -rra(ist)*nteger+!";
if !n + '" {
primes.add!n";
}
return primes;
}
}
7/21/2019 Prime Factors Kata (1)
19/37
he Fourth est
7/21/2019 Prime Factors Kata (1)
20/37
he Fourth test.package primeFactors;
import static primeFactors.PrimeFactors.generate;
import junit.framework.TestCase;
import java.util.,;
public class PrimeFactorsTest extends TestCase {
private (ist)*nteger+ list!int... ints" {
(ist)*nteger+ list 0 new -rra(ist)*nteger+!";
for !int i 1 ints"
list.add!i";
return list;
}
public void testne!" t#rows $xception {
assert$%uals!list!"&generate!'"";
}
public void testTwo!" t#rows $xception {
assert$%uals!list!/"&generate!/"";
}
public void testT#ree!" t#rows $xception {
assert$%uals!list!2"&generate!2"";
}
public void testFour!" t#rows $xception {
assert$%uals!list!/&/"&generate!3"";
}
}
package primeFactors;
import java.util.,;
public class PrimeFactors {
public static (ist)*nteger+ generate!int n" {
(ist)*nteger+ primes 0 new -rra(ist)*nteger+!";
if !n + '" {
primes.add!n";
}
return primes;
}
}
expected: but was:
7/21/2019 Prime Factors Kata (1)
21/37
he Fourth test.package primeFactors;
import static primeFactors.PrimeFactors.generate;
import junit.framework.TestCase;
import java.util.,;
public class PrimeFactorsTest extends TestCase {
private (ist)*nteger+ list!int... ints" {
(ist)*nteger+ list 0 new -rra(ist)*nteger+!";
for !int i 1 ints"
list.add!i";
return list;
}
public void testne!" t#rows $xception {
assert$%uals!list!"&generate!'"";
}
public void testTwo!" t#rows $xception {
assert$%uals!list!/"&generate!/"";
}
public void testT#ree!" t#rows $xception {
assert$%uals!list!2"&generate!2"";
}
public void testFour!" t#rows $xception {
assert$%uals!list!/&/"&generate!3"";
}
}
package primeFactors;
import java.util.,;
public class PrimeFactors {
public static (ist)*nteger+ generate!int n" {
(ist)*nteger+ primes 0 new -rra(ist)*nteger+!";
if !n + '" {
if !n4/ 00 5" {
primes.add!/";
n 60 /;
}
if !n + '"
primes.add!n"; }
return primes;
}
}
7/21/2019 Prime Factors Kata (1)
22/37
he Fifth est
7/21/2019 Prime Factors Kata (1)
23/37
he Fifth test.package primeFactors;
import static primeFactors.PrimeFactors.generate;
import junit.framework.TestCase;
import java.util.,;
public class PrimeFactorsTest extends TestCase {
private (ist)*nteger+ list!int... ints" {
(ist)*nteger+ list 0 new -rra(ist)*nteger+!";
for !int i 1 ints"
list.add!i";
return list;
}
public void testne!" t#rows $xception {
assert$%uals!list!"&generate!'"";
}
public void testTwo!" t#rows $xception {
assert$%uals!list!/"&generate!/"";
}
public void testT#ree!" t#rows $xception {
assert$%uals!list!2"&generate!2"";
}
public void testFour!" t#rows $xception {
assert$%uals!list!/&/"&generate!3"";
}
public void test7ix!" t#rows $xception {
assert$%uals!list!/&2"&generate!8"";
}
}
package primeFactors;
import java.util.,;
public class PrimeFactors {
public static (ist)*nteger+ generate!int n" {
(ist)*nteger+ primes 0 new -rra(ist)*nteger+!";
if !n + '" {
if !n4/ 00 5" {
primes.add!/";
n 60 /;
}
if !n + '"
primes.add!n"; }
return primes;
}
}
7/21/2019 Prime Factors Kata (1)
24/37
he )i$th est
7/21/2019 Prime Factors Kata (1)
25/37
he )i$th test.package primeFactors;
import static primeFactors.PrimeFactors.generate;
import junit.framework.TestCase;
import java.util.,;
public class PrimeFactorsTest extends TestCase {
private (ist)*nteger+ list!int... ints" {
(ist)*nteger+ list 0 new -rra(ist)*nteger+!";
for !int i 1 ints"
list.add!i";
return list;
}
public void testne!" t#rows $xception {
assert$%uals!list!"&generate!'"";
}
public void testTwo!" t#rows $xception {
assert$%uals!list!/"&generate!/"";
}
public void testT#ree!" t#rows $xception {
assert$%uals!list!2"&generate!2"";
}
public void testFour!" t#rows $xception {
assert$%uals!list!/&/"&generate!3"";
}
public void test7ix!" t#rows $xception {
assert$%uals!list!/&2"&generate!8"";
}
public void test$ig#t!" t#rows $xception {
assert$%uals!list!/&/&/"&generate!9"";
}
}
package primeFactors;
import java.util.,;
public class PrimeFactors {
public static (ist)*nteger+ generate!int n" {
(ist)*nteger+ primes 0 new -rra(ist)*nteger+!";
if !n + '" {
if !n4/ 00 5" {
primes.add!/";
n 60 /;
}
if !n + '"
primes.add!n"; }
return primes;
}
}
expected: but was:
7/21/2019 Prime Factors Kata (1)
26/37
he )i$th test.package primeFactors;
import static primeFactors.PrimeFactors.generate;
import junit.framework.TestCase;
import java.util.,;
public class PrimeFactorsTest extends TestCase {
private (ist)*nteger+ list!int... ints" {
(ist)*nteger+ list 0 new -rra(ist)*nteger+!";
for !int i 1 ints"
list.add!i";
return list;
}
public void testne!" t#rows $xception {
assert$%uals!list!"&generate!'"";
}
public void testTwo!" t#rows $xception {
assert$%uals!list!/"&generate!/"";
}
public void testT#ree!" t#rows $xception {
assert$%uals!list!2"&generate!2"";
}
public void testFour!" t#rows $xception {
assert$%uals!list!/&/"&generate!3"";
}
public void test7ix!" t#rows $xception {
assert$%uals!list!/&2"&generate!8"";
}
public void test$ig#t!" t#rows $xception {
assert$%uals!list!/&/&/"&generate!9"";
}
}
package primeFactors;
import java.util.,;
public class PrimeFactors {
public static (ist)*nteger+ generate!int n" {
(ist)*nteger+ primes 0 new -rra(ist)*nteger+!";
if !n + '" {
w#ile!n4/ 00 5" {
primes.add!/";
n 60 /;
}
if !n + '"
primes.add!n"; }
return primes;
}
}
! ! !
7/21/2019 Prime Factors Kata (1)
27/37
he )e&enth est
7/21/2019 Prime Factors Kata (1)
28/37
he )e&enth test.package primeFactors;import static primeFactors.PrimeFactors.generate;
import junit.framework.TestCase;
import java.util.,;
public class PrimeFactorsTest extends TestCase {
private (ist)*nteger+ list!int... ints" {
(ist)*nteger+ list 0 new -rra(ist)*nteger+!";
for !int i 1 ints"
list.add!i";
return list;
}
public void testne!" t#rows $xception {
assert$%uals!list!"&generate!'"";
}
public void testTwo!" t#rows $xception {
assert$%uals!list!/"&generate!/"";
}
public void testT#ree!" t#rows $xception {
assert$%uals!list!2"&generate!2"";
}
public void testFour!" t#rows $xception {
assert$%uals!list!/&/"&generate!3"";
}
public void test7ix!" t#rows $xception { assert$%uals!list!/&2"&generate!8"";
}
public void test$ig#t!" t#rows $xception {
assert$%uals!list!/&/&/"&generate!9"";
}
public void test:ine!" t#rows $xception {
assert$%uals!list!2&2"&generate!"";
}
}
package primeFactors;
import java.util.,;
public class PrimeFactors {
public static (ist)*nteger+ generate!int n" {
(ist)*nteger+ primes 0 new -rra(ist)*nteger+!";
if !n + '" {
w#ile !n4/ 00 5" {
primes.add!/";
n 60 /;
}
if !n + '"
primes.add!n";
}
return primes;
}
}
expected: but was:
7/21/2019 Prime Factors Kata (1)
29/37
he )e&enth test.package primeFactors;import static primeFactors.PrimeFactors.generate;
import junit.framework.TestCase;
import java.util.,;
public class PrimeFactorsTest extends TestCase {
private (ist)*nteger+ list!int... ints" {
(ist)*nteger+ list 0 new -rra(ist)*nteger+!";
for !int i 1 ints"
list.add!i";
return list;
}
public void testne!" t#rows $xception {
assert$%uals!list!"&generate!'"";
}
public void testTwo!" t#rows $xception {
assert$%uals!list!/"&generate!/"";
}
public void testT#ree!" t#rows $xception {
assert$%uals!list!2"&generate!2"";
}
public void testFour!" t#rows $xception {
assert$%uals!list!/&/"&generate!3"";
}
public void test7ix!" t#rows $xception { assert$%uals!list!/&2"&generate!8"";
}
public void test$ig#t!" t#rows $xception {
assert$%uals!list!/&/&/"&generate!9"";
}
public void test:ine!" t#rows $xception {
assert$%uals!list!2&2"&generate!"";
}
}
package primeFactors;
import java.util.,;
public class PrimeFactors {
public static (ist)*nteger+ generate!int n" {
(ist)*nteger+ primes 0 new -rra(ist)*nteger+!";
if !n + '" {
int candidate 0 /;
w#ile !n4candidate00 5" {
primes.add!candidate";
n 60 candidate;
}
if !n + '"
primes.add!n";
}
return primes;
}
}
expected: but was:
7/21/2019 Prime Factors Kata (1)
30/37
he )e&enth test.package primeFactors;import static primeFactors.PrimeFactors.generate;
import junit.framework.TestCase;
import java.util.,;
public class PrimeFactorsTest extends TestCase {
private (ist)*nteger+ list!int... ints" {
(ist)*nteger+ list 0 new -rra(ist)*nteger+!";
for !int i 1 ints"
list.add!i";
return list;
}
public void testne!" t#rows $xception {
assert$%uals!list!"&generate!'"";
}
public void testTwo!" t#rows $xception {
assert$%uals!list!/"&generate!/"";
}
public void testT#ree!" t#rows $xception {
assert$%uals!list!2"&generate!2"";
}
public void testFour!" t#rows $xception {
assert$%uals!list!/&/"&generate!3"";
}
public void test7ix!" t#rows $xception { assert$%uals!list!/&2"&generate!8"";
}
public void test$ig#t!" t#rows $xception {
assert$%uals!list!/&/&/"&generate!9"";
}
public void test:ine!" t#rows $xception {
assert$%uals!list!2&2"&generate!"";
}
}
package primeFactors;
import java.util.,;
public class PrimeFactors {
public static (ist)*nteger+ generate!int n" {
(ist)*nteger+ primes 0 new -rra(ist)*nteger+!";
if !n + '" {
int candidate 0 /;
w#ile !n 4 candidate 00 5" {
primes.add!candidate";
n 60 candidate;
}
}
if !n + '"
primes.add!n";
return primes;
}
}
expected: but was:
7/21/2019 Prime Factors Kata (1)
31/37
he )e&enth test.package primeFactors;import static primeFactors.PrimeFactors.generate;
import junit.framework.TestCase;
import java.util.,;
public class PrimeFactorsTest extends TestCase {
private (ist)*nteger+ list!int... ints" {
(ist)*nteger+ list 0 new -rra(ist)*nteger+!";
for !int i 1 ints"
list.add!i";
return list;
}
public void testne!" t#rows $xception {
assert$%uals!list!"&generate!'"";
}
public void testTwo!" t#rows $xception {
assert$%uals!list!/"&generate!/"";
}
public void testT#ree!" t#rows $xception {
assert$%uals!list!2"&generate!2"";
}
public void testFour!" t#rows $xception {
assert$%uals!list!/&/"&generate!3"";
}
public void test7ix!" t#rows $xception { assert$%uals!list!/&2"&generate!8"";
}
public void test$ig#t!" t#rows $xception {
assert$%uals!list!/&/&/"&generate!9"";
}
public void test:ine!" t#rows $xception {
assert$%uals!list!2&2"&generate!"";
}
}
package primeFactors;
import java.util.,;
public class PrimeFactors {
public static (ist)*nteger+ generate!int n" {
(ist)*nteger+ primes 0 new -rra(ist)*nteger+!";
int candidate 0 /;
if !n + '" {
w#ile !n 4 candidate 00 5" {
primes.add!candidate";
n 60 candidate;
}
}
if !n + '"
primes.add!n";
return primes;
}
}
expected: but was:
7/21/2019 Prime Factors Kata (1)
32/37
he )e&enth test.package primeFactors;import static primeFactors.PrimeFactors.generate;
import junit.framework.TestCase;
import java.util.,;
public class PrimeFactorsTest extends TestCase {
private (ist)*nteger+ list!int... ints" {
(ist)*nteger+ list 0 new -rra(ist)*nteger+!";
for !int i 1 ints"
list.add!i";
return list;
}
public void testne!" t#rows $xception {
assert$%uals!list!"&generate!'"";
}
public void testTwo!" t#rows $xception {
assert$%uals!list!/"&generate!/"";
}
public void testT#ree!" t#rows $xception {
assert$%uals!list!2"&generate!2"";
}
public void testFour!" t#rows $xception {
assert$%uals!list!/&/"&generate!3"";
}
public void test7ix!" t#rows $xception { assert$%uals!list!/&2"&generate!8"";
}
public void test$ig#t!" t#rows $xception {
assert$%uals!list!/&/&/"&generate!9"";
}
public void test:ine!" t#rows $xception {
assert$%uals!list!2&2"&generate!"";
}
}
package primeFactors;
import java.util.,;
public class PrimeFactors {
public static (ist)*nteger+ generate!int n" {
(ist)*nteger+ primes 0 new -rra(ist)*nteger+!";
int candidate 0 /;
if !n + '" {
w#ile !n 4 candidate 00 5" {
primes.add!candidate";
n 60 candidate;
}
}
if !n + '"
primes.add!n";
return primes;
}
}
expected: but was:
7/21/2019 Prime Factors Kata (1)
33/37
he )e&enth test.package primeFactors;import static primeFactors.PrimeFactors.generate;
import junit.framework.TestCase;
import java.util.,;
public class PrimeFactorsTest extends TestCase {
private (ist)*nteger+ list!int... ints" {
(ist)*nteger+ list 0 new -rra(ist)*nteger+!";
for !int i 1 ints"
list.add!i";
return list;
}
public void testne!" t#rows $xception {
assert$%uals!list!"&generate!'"";
}
public void testTwo!" t#rows $xception {
assert$%uals!list!/"&generate!/"";
}
public void testT#ree!" t#rows $xception {
assert$%uals!list!2"&generate!2"";
}
public void testFour!" t#rows $xception {
assert$%uals!list!/&/"&generate!3"";
}
public void test7ix!" t#rows $xception { assert$%uals!list!/&2"&generate!8"";
}
public void test$ig#t!" t#rows $xception {
assert$%uals!list!/&/&/"&generate!9"";
}
public void test:ine!" t#rows $xception {
assert$%uals!list!2&2"&generate!"";
}
}
package primeFactors;
import java.util.,;
public class PrimeFactors {
public static (ist)*nteger+ generate!int n" {
(ist)*nteger+ primes 0 new -rra(ist)*nteger+!";
int candidate 0 /;
w#ile!n + '" {
w#ile !n 4 candidate 00 5" {
primes.add!candidate";
n 60 candidate;
}
candidate
7/21/2019 Prime Factors Kata (1)
34/37
he )e&enth test.package primeFactors;import static primeFactors.PrimeFactors.generate;
import junit.framework.TestCase;
import java.util.,;
public class PrimeFactorsTest extends TestCase {
private (ist)*nteger+ list!int... ints" {
(ist)*nteger+ list 0 new -rra(ist)*nteger+!";
for !int i 1 ints"
list.add!i";
return list;
}
public void testne!" t#rows $xception {
assert$%uals!list!"&generate!'"";
}
public void testTwo!" t#rows $xception {
assert$%uals!list!/"&generate!/"";
}
public void testT#ree!" t#rows $xception {
assert$%uals!list!2"&generate!2"";
}
public void testFour!" t#rows $xception {
assert$%uals!list!/&/"&generate!3"";
}
public void test7ix!" t#rows $xception { assert$%uals!list!/&2"&generate!8"";
}
public void test$ig#t!" t#rows $xception {
assert$%uals!list!/&/&/"&generate!9"";
}
public void test:ine!" t#rows $xception {
assert$%uals!list!2&2"&generate!"";
}
}
package primeFactors;
import java.util.,;
public class PrimeFactors {
public static (ist)*nteger+ generate!int n" {
(ist)*nteger+ primes 0 new -rra(ist)*nteger+!";
int candidate 0 /;
w#ile !n + '" {
w#ile !n 4 candidate 00 5" {
primes.add!candidate";
n 60 candidate;
}
candidate
7/21/2019 Prime Factors Kata (1)
35/37
he )e&enth test.package primeFactors;import static primeFactors.PrimeFactors.generate;
import junit.framework.TestCase;
import java.util.,;
public class PrimeFactorsTest extends TestCase {
private (ist)*nteger+ list!int... ints" {
(ist)*nteger+ list 0 new -rra(ist)*nteger+!";
for !int i 1 ints"
list.add!i";
return list;
}
public void testne!" t#rows $xception {
assert$%uals!list!"&generate!'"";
}
public void testTwo!" t#rows $xception {
assert$%uals!list!/"&generate!/"";
}
public void testT#ree!" t#rows $xception {
assert$%uals!list!2"&generate!2"";
}
public void testFour!" t#rows $xception {
assert$%uals!list!/&/"&generate!3"";
}
public void test7ix!" t#rows $xception { assert$%uals!list!/&2"&generate!8"";
}
public void test$ig#t!" t#rows $xception {
assert$%uals!list!/&/&/"&generate!9"";
}
public void test:ine!" t#rows $xception {
assert$%uals!list!2&2"&generate!"";
}
}
package primeFactors;
import java.util.,;
public class PrimeFactors {
public static (ist)*nteger+ generate!int n" {
(ist)*nteger+ primes 0 new -rra(ist)*nteger+!";
int candidate 0 /;
w#ile !n + '" {
for!; n4candidate 00 5; n60candidate"
primes.add!candidate";
candidate
7/21/2019 Prime Factors Kata (1)
36/37
he )e&enth test.package primeFactors;import static primeFactors.PrimeFactors.generate;
import junit.framework.TestCase;
import java.util.,;
public class PrimeFactorsTest extends TestCase {
private (ist)*nteger+ list!int... ints" {
(ist)*nteger+ list 0 new -rra(ist)*nteger+!";
for !int i 1 ints"
list.add!i";
return list;
}
public void testne!" t#rows $xception {
assert$%uals!list!"&generate!'"";
}
public void testTwo!" t#rows $xception {
assert$%uals!list!/"&generate!/"";
}
public void testT#ree!" t#rows $xception {
assert$%uals!list!2"&generate!2"";
}
public void testFour!" t#rows $xception {
assert$%uals!list!/&/"&generate!3"";
}
public void test7ix!" t#rows $xception { assert$%uals!list!/&2"&generate!8"";
}
public void test$ig#t!" t#rows $xception {
assert$%uals!list!/&/&/"&generate!9"";
}
public void test:ine!" t#rows $xception {
assert$%uals!list!2&2"&generate!"";
}
}
package primeFactors;
import java.util.,;
public class PrimeFactors {
public static (ist)*nteger+ generate!int n" {
(ist)*nteger+ primes 0 new -rra(ist)*nteger+!";
for !int candidate 0 /; n + '; candidate
7/21/2019 Prime Factors Kata (1)
37/37
>?@
Top Related