SlideShare a Scribd company logo
Тесты — хорошо :)
 Когда писать тесты?

Сколько писать тестов?
Tdd
1.You may not write production code until you
  have written a failing unit test.
2.You may not write more of a unit test than is
  sufficient to fail, and not compiling is failing.
3.You may not write more production code than
  is sufficient to pass the currently failing test.




            Три закона TDD
               «Clean Code», Robert C.Martin
Prime Factors Kata


               Object Mentor, Inc.
                 www.objectmentor.com
                 blog.objectmentor.com




fitnesse.org                             www.junit.org
                                                          Copyright © 2005 by Object Mentor, Inc
                                                         All copies must retain this page unchanged.
1

package primeFactors;

import junit.framework.TestCase;

public class PrimeFactorsTest extends TestCase {
  public void testOne() throws Exception {
    assertEquals(list(),PrimeFactors.generate(1));
  }
}
1

package primeFactors;

import junit.framework.TestCase;

import java.util.List;

public class PrimeFactorsTest extends TestCase {
  public void testOne() throws Exception {
    assertEquals(list(),PrimeFactors.generate(1));
  }

    private List<Integer> list() {
      return null;
    }
}
1

package primeFactors;                                package primeFactors;

import junit.framework.TestCase;                     public class PrimeFactors {
                                                     }
import java.util.List;

public class PrimeFactorsTest extends TestCase {
  public void testOne() throws Exception {
    assertEquals(list(),PrimeFactors.generate(1));
  }

    private List<Integer> list() {
      return null;
    }
}
1

package primeFactors;                                package primeFactors;

import junit.framework.TestCase;                     import java.util.*;

import java.util.List;                               public class PrimeFactors {
                                                       public static List<Integer> generate(int n) {
public class PrimeFactorsTest extends TestCase {         return new ArrayList<Integer>();
  public void testOne() throws Exception {             }
    assertEquals(list(),PrimeFactors.generate(1));   }
  }

    private List<Integer> list() {
      return null;
    }
}
1

package primeFactors;                                package primeFactors;

import junit.framework.TestCase;                     import java.util.*;

import java.util.*;                                  public class PrimeFactors {
                                                       public static List<Integer> generate(int n) {
public class PrimeFactorsTest extends TestCase {         return new ArrayList<Integer>();
  public void testOne() throws Exception {             }
    assertEquals(list(),PrimeFactors.generate(1));   }
  }

    private List<Integer> list() {
      return new ArrayList<Integer>();
    }
}
1

package primeFactors;                                  package primeFactors;

import junit.framework.TestCase;                       import java.util.*;

import java.util.*;                                    public class PrimeFactors {
                                                         public static List<Integer> generate(int n) {
public class PrimeFactorsTest extends TestCase {           return new ArrayList<Integer>();
  private List<Integer> list() {                         }
    return new ArrayList<Integer>();                   }
  }

    public void testOne() throws Exception {
      assertEquals(list(),PrimeFactors.generate(1));
    }
}
1             2

package primeFactors;                                   package primeFactors;

import junit.framework.TestCase;                        import java.util.*;

import java.util.*;                                     public class PrimeFactors {
                                                          public static List<Integer> generate(int n) {
public class PrimeFactorsTest extends TestCase {            return new ArrayList<Integer>();
  private List<Integer> list() {                          }
    return new ArrayList<Integer>();                    }
  }

    public void testOne() throws Exception {
      assertEquals(list(),PrimeFactors.generate(1));
    }

    public void testTwo() throws Exception {
      assertEquals(list(2),PrimeFactors.generate(2));
    }
}
1             2

package primeFactors;                                             package primeFactors;

import junit.framework.TestCase;                                  import java.util.*;

import java.util.*;                                               public class PrimeFactors {
                                                                    public static List<Integer> generate(int n) {
public class PrimeFactorsTest extends TestCase {                      return new ArrayList<Integer>();
  private List<Integer> list(int... ints) {             varargs     }
    List<Integer> list = new ArrayList<Integer>();                }
    for (int i : ints)
     list.add(i);
    return list;
  }

    public void testOne() throws Exception {
      assertEquals(list(),PrimeFactors.generate(1));
    }

    public void testTwo() throws Exception {
      assertEquals(list(2),PrimeFactors.generate(2));
    }
}
1             2

package primeFactors;                                   package primeFactors;

import junit.framework.TestCase;                        import java.util.*;

import java.util.*;                                     public class PrimeFactors {
                                                          public static List<Integer> generate(int n) {
public class PrimeFactorsTest extends TestCase {             List<Integer> primes = new ArrayList<Integer>();
  private List<Integer> list(int... ints) {                  if (n > 1) {
    List<Integer> list = new ArrayList<Integer>();            primes.add(2);
    for (int i : ints)                                      }
      list.add(i);                                           return primes;
    return list;                                          }
  }                                                     }

    public void testOne() throws Exception {
      assertEquals(list(),PrimeFactors.generate(1));
    }

    public void testTwo() throws Exception {
      assertEquals(list(2),PrimeFactors.generate(2));
    }
}
1              2

package primeFactors;                                package primeFactors;

import static primeFactors.PrimeFactors.generate;    import java.util.*;
 import junit.framework.TestCase;
 import java.util.*;                                 public class PrimeFactors {
                                                       public static List<Integer> generate(int n) {
public class PrimeFactorsTest extends TestCase {         List<Integer> primes = new ArrayList<Integer>();
  private List<Integer> list(int... ints) {              if (n > 1) {
    List<Integer> list = new ArrayList<Integer>();         primes.add(2);
    for (int i : ints)                                   }
      list.add(i);                                       return primes;
    return list;                                       }
  }                                                  }

    public void testOne() throws Exception {
      assertEquals(list(),generate(1));
    }

    public void testTwo() throws Exception {
      assertEquals(list(2),generate(2));
    }
}
1               2               3

package primeFactors;                                    package primeFactors;

import static primeFactors.PrimeFactors.generate;        import java.util.*;
import junit.framework.TestCase;
import java.util.*;                                      public class PrimeFactors {
                                                           public static List<Integer> generate(int n) {
public class PrimeFactorsTest extends TestCase {             List<Integer> primes = new ArrayList<Integer>();
  private List<Integer> list(int... ints) {                  if (n > 1) {
    List<Integer> list = new ArrayList<Integer>();             primes.add(2);
    for (int i : ints)                                       }
      list.add(i);                                           return primes;
    return list;                                           }
  }                                                      }

    public void testOne() throws Exception {
      assertEquals(list(),generate(1));
    }

    public void testTwo() throws Exception {
      assertEquals(list(2),generate(2));
    }

    public void testThree() throws Exception {
      assertEquals(list(3),generate(3));
    }
}
1              2                3

package primeFactors;                                    package primeFactors;

import static primeFactors.PrimeFactors.generate;        import java.util.*;
import junit.framework.TestCase;
import java.util.*;                                      public class PrimeFactors {
                                                           public static List<Integer> generate(int n) {
public class PrimeFactorsTest extends TestCase {             List<Integer> primes = new ArrayList<Integer>();
  private List<Integer> list(int... ints) {                  if (n > 1) {
    List<Integer> list = new ArrayList<Integer>();             primes.add(n);
    for (int i : ints)                                       }
      list.add(i);                                           return primes;
    return list;                                           }
  }                                                      }

    public void testOne() throws Exception {
      assertEquals(list(),generate(1));
    }

    public void testTwo() throws Exception {
      assertEquals(list(2),generate(2));
    }

    public void testThree() throws Exception {
      assertEquals(list(3),generate(3));
    }
}
1               2               3   4

package primeFactors;                                        package primeFactors;

import static primeFactors.PrimeFactors.generate;            import java.util.*;
import junit.framework.TestCase;
import java.util.*;                                          public class PrimeFactors {
                                                               public static List<Integer> generate(int n) {
public class PrimeFactorsTest extends TestCase {                 List<Integer> primes = new ArrayList<Integer>();
  private List<Integer> list(int... ints) {                      if (n > 1) {
    List<Integer> list = new ArrayList<Integer>();                 primes.add(n);
    for (int i : ints)                                           }
      list.add(i);                                               return primes;
    return list;                                               }
  }                                                          }

    public void testOne() throws Exception {
      assertEquals(list(),generate(1));
    }

    public void testTwo() throws Exception {
      assertEquals(list(2),generate(2));
    }

    public void testThree() throws Exception {
      assertEquals(list(3),generate(3));
    }

    public void testFour() throws Exception {
      assertEquals(list(2,2),generate(4));
    }
}
1              2                3   4

package primeFactors;                                        package primeFactors;

import static primeFactors.PrimeFactors.generate;            import java.util.*;
import junit.framework.TestCase;
import java.util.*;                                          public class PrimeFactors {
                                                               public static List<Integer> generate(int n) {
public class PrimeFactorsTest extends TestCase {                 List<Integer> primes = new ArrayList<Integer>();
  private List<Integer> list(int... ints) {                      if (n > 1) {
    List<Integer> list = new ArrayList<Integer>();                 if (n%2 == 0) {
    for (int i : ints)                                               primes.add(2);
      list.add(i);                                                   n /= 2;
    return list;                                                   }
  }                                                                 if (n > 1)
                                                                      primes.add(n);
    public void testOne() throws Exception {                     }
      assertEquals(list(),generate(1));                          return primes;
    }                                                          }
                                                             }
    public void testTwo() throws Exception {
      assertEquals(list(2),generate(2));
    }

    public void testThree() throws Exception {
      assertEquals(list(3),generate(3));
    }

    public void testFour() throws Exception {
      assertEquals(list(2,2),generate(4));
    }
}
1               2               3   4            5

package primeFactors;                                        package primeFactors;

import static primeFactors.PrimeFactors.generate;            import java.util.*;
import junit.framework.TestCase;
import java.util.*;                                          public class PrimeFactors {
                                                               public static List<Integer> generate(int n) {
public class PrimeFactorsTest extends TestCase {                 List<Integer> primes = new ArrayList<Integer>();
  private List<Integer> list(int... ints) {                      if (n > 1) {
    List<Integer> list = new ArrayList<Integer>();                 if (n%2 == 0) {
    for (int i : ints)                                               primes.add(2);
      list.add(i);                                                   n /= 2;
    return list;                                                   }
  }                                                                 if (n > 1)
                                                                      primes.add(n);
    public void testOne() throws Exception {                     }
      assertEquals(list(),generate(1));                          return primes;
    }                                                          }
                                                             }
    public void testTwo() throws Exception {
      assertEquals(list(2),generate(2));
    }

    public void testThree() throws Exception {
      assertEquals(list(3),generate(3));
    }

    public void testFour() throws Exception {
      assertEquals(list(2,2),generate(4));
    }

    public void testFive() throws Exception {
      assertEquals(list(2,3),generate(6));
    }
}
1               2               3   4            5               6

package primeFactors;                                        package primeFactors;

import static primeFactors.PrimeFactors.generate;            import java.util.*;
import junit.framework.TestCase;
import java.util.*;                                          public class PrimeFactors {
                                                               public static List<Integer> generate(int n) {
public class PrimeFactorsTest extends TestCase {                 List<Integer> primes = new ArrayList<Integer>();
  private List<Integer> list(int... ints) {                      if (n > 1) {
    List<Integer> list = new ArrayList<Integer>();                 if (n%2 == 0) {
    for (int i : ints)                                               primes.add(2);
      list.add(i);                                                   n /= 2;
    return list;                                                   }
  }                                                                if (n > 1)
                                                                     primes.add(n);
    public void testOne() throws Exception {                     }
      assertEquals(list(),generate(1));                          return primes;
    }                                                          }
                                                             }
    public void testTwo() throws Exception {
      assertEquals(list(2),generate(2));
    }

    public void testThree() throws Exception {
      assertEquals(list(3),generate(3));
    }

    public void testFour() throws Exception {
      assertEquals(list(2,2),generate(4));
    }

    public void testFive() throws Exception {
      assertEquals(list(2,3),generate(6));
    }

    public void testSix() throws Exception {
      assertEquals(list(2,2,2),generate(8));
    }
}
1              2                3   4            5               6

package primeFactors;                                        package primeFactors;

import static primeFactors.PrimeFactors.generate;            import java.util.*;
import junit.framework.TestCase;
import java.util.*;                                          public class PrimeFactors {
                                                               public static List<Integer> generate(int n) {
public class PrimeFactorsTest extends TestCase {                 List<Integer> primes = new ArrayList<Integer>();
  private List<Integer> list(int... ints) {                      if (n > 1) {
    List<Integer> list = new ArrayList<Integer>();                 while (n%2 == 0) {
    for (int i : ints)                                               primes.add(2);
      list.add(i);                                                   n /= 2;               ! ! !
    return list;                                                   }
  }                                                                if (n > 1)
                                                                     primes.add(n);
    public void testOne() throws Exception {                     }
      assertEquals(list(),generate(1));                          return primes;
    }                                                          }
                                                             }
    public void testTwo() throws Exception {
      assertEquals(list(2),generate(2));
    }

    public void testThree() throws Exception {
      assertEquals(list(3),generate(3));
    }

    public void testFour() throws Exception {
      assertEquals(list(2,2),generate(4));
    }

    public void testFive() throws Exception {
      assertEquals(list(2,3),generate(6));
    }

    public void testSix() throws Exception {
      assertEquals(list(2,2,2),generate(8));
    }
}
1               2               3   4            5               6               7
package primeFactors;

import static primeFactors.PrimeFactors.generate;
import junit.framework.TestCase;
import java.util.*;                                          package primeFactors;

public class PrimeFactorsTest extends TestCase {             import java.util.*;
  private List<Integer> list(int... ints) {
    List<Integer> list = new ArrayList<Integer>();           public class PrimeFactors {
    for (int i : ints)                                         public static List<Integer> generate(int n) {
      list.add(i);                                               List<Integer> primes = new ArrayList<Integer>();
    return list;                                                 if (n > 1) {
  }                                                                while (n%2 == 0) {
                                                                     primes.add(2);
    public void testOne() throws Exception {                         n /= 2;
      assertEquals(list(),generate(1));                            }
    }                                                              if (n > 1)
                                                                     primes.add(n);
    public void testTwo() throws Exception {                     }
      assertEquals(list(2),generate(2));
                                                                 return primes;
    }
                                                               }
                                                             }
    public void testThree() throws Exception {
      assertEquals(list(3),generate(3));
    }

    public void testFour() throws Exception {
      assertEquals(list(2,2),generate(4));
    }

    public void testFive() throws Exception {
      assertEquals(list(2,3),generate(6));
    }

    public void testSix() throws Exception {
      assertEquals(list(2,2,2),generate(8));
    }

    public void testSeven() throws Exception {
       assertEquals(list(3,3),generate(9));
     }
}
1              2                3   4            5               6               7
package primeFactors;

import static primeFactors.PrimeFactors.generate;
import junit.framework.TestCase;
import java.util.*;                                          package primeFactors;

public class PrimeFactorsTest extends TestCase {             import java.util.*;
  private List<Integer> list(int... ints) {
    List<Integer> list = new ArrayList<Integer>();           public class PrimeFactors {
    for (int i : ints)                                         public static List<Integer> generate(int n) {
      list.add(i);                                               List<Integer> primes = new ArrayList<Integer>();
    return list;                                                 if (n > 1) {
  }                                                                int candidate = 2;
                                                                   while (n%candidate == 0) {
    public void testOne() throws Exception {                         primes.add(candidate);
      assertEquals(list(),generate(1));                              n /= candidate;
    }                                                              }
                                                                   if (n > 1)
    public void testTwo() throws Exception {                         primes.add(n);
      assertEquals(list(2),generate(2));
                                                                 }
    }
                                                                 return primes;
                                                               }
    public void testThree() throws Exception {
      assertEquals(list(3),generate(3));                     }
    }

    public void testFour() throws Exception {
      assertEquals(list(2,2),generate(4));
    }

    public void testFive() throws Exception {
      assertEquals(list(2,3),generate(6));
    }

    public void testSix() throws Exception {
      assertEquals(list(2,2,2),generate(8));
    }

    public void testSeven() throws Exception {
      assertEquals(list(3,3),generate(9));
    }
}
1              2                3   4            5               6               7
package primeFactors;

import static primeFactors.PrimeFactors.generate;
import junit.framework.TestCase;
import java.util.*;                                          package primeFactors;

public class PrimeFactorsTest extends TestCase {             import java.util.*;
  private List<Integer> list(int... ints) {
    List<Integer> list = new ArrayList<Integer>();           public class PrimeFactors {
    for (int i : ints)                                         public static List<Integer> generate(int n) {
      list.add(i);                                               List<Integer> primes = new ArrayList<Integer>();
    return list;                                                 if (n > 1) {
  }                                                                 int candidate = 2;
                                                                    while (n % candidate == 0) {
    public void testOne() throws Exception {                          primes.add(candidate);
      assertEquals(list(),generate(1));                               n /= candidate;
    }                                                               }
                                                                 }
    public void testTwo() throws Exception {                     if (n > 1)
      assertEquals(list(2),generate(2));
                                                                   primes.add(n);
    }
                                                                 return primes;
                                                               }
    public void testThree() throws Exception {
      assertEquals(list(3),generate(3));                     }
    }

    public void testFour() throws Exception {
      assertEquals(list(2,2),generate(4));
    }

    public void testFive() throws Exception {
      assertEquals(list(2,3),generate(6));
    }

    public void testSix() throws Exception {
      assertEquals(list(2,2,2),generate(8));
    }

    public void testSeven() throws Exception {
      assertEquals(list(3,3),generate(9));
    }
}
1              2                3   4            5               6               7
package primeFactors;

import static primeFactors.PrimeFactors.generate;
import junit.framework.TestCase;
import java.util.*;                                          package primeFactors;

public class PrimeFactorsTest extends TestCase {             import java.util.*;
  private List<Integer> list(int... ints) {
    List<Integer> list = new ArrayList<Integer>();           public class PrimeFactors {
    for (int i : ints)                                         public static List<Integer> generate(int n) {
      list.add(i);                                               List<Integer> primes = new ArrayList<Integer>();
    return list;                                                 int candidate = 2;
  }                                                              if (n > 1) {
                                                                   while (n % candidate == 0) {
    public void testOne() throws Exception {                         primes.add(candidate);
      assertEquals(list(),generate(1));                              n /= candidate;
    }                                                              }
                                                                 }
    public void testTwo() throws Exception {                     if (n > 1)
      assertEquals(list(2),generate(2));
                                                                   primes.add(n);
    }
                                                                 return primes;
                                                               }
    public void testThree() throws Exception {
      assertEquals(list(3),generate(3));                     }
    }

    public void testFour() throws Exception {
      assertEquals(list(2,2),generate(4));
    }

    public void testFive() throws Exception {
      assertEquals(list(2,3),generate(6));
    }

    public void testSix() throws Exception {
      assertEquals(list(2,2,2),generate(8));
    }

    public void testSeven() throws Exception {
      assertEquals(list(3,3),generate(9));
    }
}
1              2                3   4            5               6               7
package primeFactors;

import static primeFactors.PrimeFactors.generate;
import junit.framework.TestCase;
import java.util.*;                                          package primeFactors;

public class PrimeFactorsTest extends TestCase {             import java.util.*;
  private List<Integer> list(int... ints) {
    List<Integer> list = new ArrayList<Integer>();           public class PrimeFactors {
    for (int i : ints)                                         public static List<Integer> generate(int n) {
      list.add(i);                                               List<Integer> primes = new ArrayList<Integer>();
    return list;                                                 int candidate = 2;
  }                                                              if (n > 1) {
                                                                   while (n % candidate == 0) {
    public void testOne() throws Exception {                         primes.add(candidate);
      assertEquals(list(),generate(1));                              n /= candidate;
    }                                                              }
                                                                 }
    public void testTwo() throws Exception {                     if (n > 1)
      assertEquals(list(2),generate(2));
                                                                   primes.add(n);
    }
                                                                 return primes;
                                                               }
    public void testThree() throws Exception {
      assertEquals(list(3),generate(3));                     }
    }

    public void testFour() throws Exception {
      assertEquals(list(2,2),generate(4));
    }

    public void testFive() throws Exception {
      assertEquals(list(2,3),generate(6));
    }

    public void testSix() throws Exception {
      assertEquals(list(2,2,2),generate(8));
    }

    public void testSeven() throws Exception {
      assertEquals(list(3,3),generate(9));
    }
}
1              2                3   4            5               6               7
package primeFactors;

import static primeFactors.PrimeFactors.generate;
import junit.framework.TestCase;
import java.util.*;                                          package primeFactors;

public class PrimeFactorsTest extends TestCase {             import java.util.*;
  private List<Integer> list(int... ints) {
    List<Integer> list = new ArrayList<Integer>();           public class PrimeFactors {
    for (int i : ints)                                         public static List<Integer> generate(int n) {
      list.add(i);                                               List<Integer> primes = new ArrayList<Integer>();
    return list;                                                 int candidate = 2;
  }                                                              while (n > 1) {
                                                                    while (n % candidate == 0) { ! ! !
    public void testOne() throws Exception {                          primes.add(candidate);
      assertEquals(list(),generate(1));                               n /= candidate;
    }                                                               }
                                                                   candidate++;
    public void testTwo() throws Exception {                     }
      assertEquals(list(2),generate(2));
                                                                 if (n > 1)
    }
                                                                    primes.add(n);
                                                                 return primes;
    public void testThree() throws Exception {
      assertEquals(list(3),generate(3));                       }
    }                                                        }

    public void testFour() throws Exception {
      assertEquals(list(2,2),generate(4));
    }

    public void testFive() throws Exception {
      assertEquals(list(2,3),generate(6));
    }

    public void testSix() throws Exception {
      assertEquals(list(2,2,2),generate(8));
    }

    public void testSeven() throws Exception {
      assertEquals(list(3,3),generate(9));
    }
}
1              2                3   4            5               6               7
package primeFactors;

import static primeFactors.PrimeFactors.generate;
import junit.framework.TestCase;
import java.util.*;                                          package primeFactors;

public class PrimeFactorsTest extends TestCase {             import java.util.*;
  private List<Integer> list(int... ints) {
    List<Integer> list = new ArrayList<Integer>();           public class PrimeFactors {
    for (int i : ints)                                         public static List<Integer> generate(int n) {
      list.add(i);                                               List<Integer> primes = new ArrayList<Integer>();
    return list;                                                 int candidate = 2;
  }                                                              while (n > 1) {
                                                                   while (n % candidate == 0) {
    public void testOne() throws Exception {                         primes.add(candidate);
      assertEquals(list(),generate(1));                              n /= candidate;
    }                                                              }
                                                                   candidate++;
    public void testTwo() throws Exception {                     }
      assertEquals(list(2),generate(2));
                                                                 return primes;
    }
                                                               }
                                                             }
    public void testThree() throws Exception {
      assertEquals(list(3),generate(3));
    }

    public void testFour() throws Exception {
      assertEquals(list(2,2),generate(4));
    }

    public void testFive() throws Exception {
      assertEquals(list(2,3),generate(6));
    }

    public void testSix() throws Exception {
      assertEquals(list(2,2,2),generate(8));
    }

    public void testSeven() throws Exception {
      assertEquals(list(3,3),generate(9));
    }
}
1               2               3   4                5           6               7
package primeFactors;

import static primeFactors.PrimeFactors.generate;
import junit.framework.TestCase;
import java.util.*;                                          package primeFactors;

public class PrimeFactorsTest extends TestCase {             import java.util.*;
  private List<Integer> list(int... ints) {
    List<Integer> list = new ArrayList<Integer>();           public class PrimeFactors {
    for (int i : ints)                                         public static List<Integer> generate(int n) {
      list.add(i);                                               List<Integer> primes = new ArrayList<Integer>();
    return list;                                                 int candidate = 2;
  }                                                              while (n > 1) {
                                                                   for (; n%candidate == 0; n/=candidate)
    public void testOne() throws Exception {                         primes.add(candidate);
      assertEquals(list(),generate(1));
    }                                                                  candidate++;
                                                                     }
    public void testTwo() throws Exception {                         return primes;
      assertEquals(list(2),generate(2));
                                                                 }
    }
                                                             }
    public void testThree() throws Exception {
      assertEquals(list(3),generate(3));
    }

    public void testFour() throws Exception {
      assertEquals(list(2,2),generate(4));
    }

    public void testFive() throws Exception {
      assertEquals(list(2,3),generate(6));
    }

    public void testSix() throws Exception {
      assertEquals(list(2,2,2),generate(8));
    }

    public void testSeven() throws Exception {
      assertEquals(list(3,3),generate(9));
    }
}
1               2               3   4                5               6               7
package primeFactors;

import static primeFactors.PrimeFactors.generate;
import junit.framework.TestCase;
import java.util.*;                                          package primeFactors;

public class PrimeFactorsTest extends TestCase {             import java.util.*;
  private List<Integer> list(int... ints) {
    List<Integer> list = new ArrayList<Integer>();           public class PrimeFactors {
    for (int i : ints)                                         public static List<Integer> generate(int n) {
      list.add(i);                                               List<Integer> primes = new ArrayList<Integer>();
    return list;
  }                                                                  for (int candidate = 2; n > 1; candidate++)
                                                                       for (; n%candidate == 0; n/=candidate)
    public void testOne() throws Exception {                             primes.add(candidate);
      assertEquals(list(),generate(1));
    }                                                                return primes;
                                                                 }
    public void testTwo() throws Exception {                 }
      assertEquals(list(2),generate(2));
    }

    public void testThree() throws Exception {
      assertEquals(list(3),generate(3));
    }

    public void testFour() throws Exception {
      assertEquals(list(2,2),generate(4));
    }

    public void testFive() throws Exception {
      assertEquals(list(2,3),generate(6));
    }

    public void testSix() throws Exception {
      assertEquals(list(2,2,2),generate(8));
    }

    public void testSeven() throws Exception {
      assertEquals(list(3,3),generate(9));
    }
}
1               2               3   4                5               6               7
package primeFactors;

import static primeFactors.PrimeFactors.generate;
import junit.framework.TestCase;
import java.util.*;                                          package primeFactors;

public class PrimeFactorsTest extends TestCase {             import java.util.*;
  private List<Integer> list(int... ints) {
    List<Integer> list = new ArrayList<Integer>();           public class PrimeFactors {
    for (int i : ints)                                         public static List<Integer> generate(int n) {
      list.add(i);                                               List<Integer> primes = new ArrayList<Integer>();
    return list;
  }                                                                  for (int candidate = 2; n > 1; candidate++)
                                                                       for (; n%candidate == 0; n/=candidate)
    public void testOne() throws Exception {                             primes.add(candidate);
      assertEquals(list(),generate(1));
    }                                                                return primes;
                                                                 }
    public void testTwo() throws Exception {                 }
      assertEquals(list(2),generate(2));
    }

    public void testThree() throws Exception {
      assertEquals(list(3),generate(3));
    }

    public void testFour() throws Exception {

    }
      assertEquals(list(2,2),generate(4));


    public void testFive() throws Exception {
                                                                      3 строчки кода!!!
      assertEquals(list(2,3),generate(6));
    }

    public void testSix() throws Exception {
      assertEquals(list(2,2,2),generate(8));
    }

    public void testSeven() throws Exception {
      assertEquals(list(3,3),generate(9));
    }
}
Tdd
Tdd
Tdd
Tdd

More Related Content

DOCX
Registro de venta
lupe ga
 
PPTX
Junit 5 - Maior e melhor
Tiago de Freitas Lima
 
DOCX
Ejemplo radio
lupe ga
 
DOCX
XTW_Import
Luther Quinn
 
PDF
Art of unit testing: How developer should care about code quality
Dmytro Patserkovskyi
 
PDF
T.Y.B.S.CS Advance Java Practicals Sem 5 Mumbai University
Niraj Bharambe
 
PDF
The Ring programming language version 1.10 book - Part 42 of 212
Mahmoud Samir Fayed
 
PPTX
Pragmatic unittestingwithj unit
liminescence
 
Registro de venta
lupe ga
 
Junit 5 - Maior e melhor
Tiago de Freitas Lima
 
Ejemplo radio
lupe ga
 
XTW_Import
Luther Quinn
 
Art of unit testing: How developer should care about code quality
Dmytro Patserkovskyi
 
T.Y.B.S.CS Advance Java Practicals Sem 5 Mumbai University
Niraj Bharambe
 
The Ring programming language version 1.10 book - Part 42 of 212
Mahmoud Samir Fayed
 
Pragmatic unittestingwithj unit
liminescence
 

What's hot (20)

PDF
Java8 tgtbatu javaone
Brian Vermeer
 
PDF
Java(8) The Good, The Bad and the Ugly
Brian Vermeer
 
PDF
Guice2.0
Masaaki Yonebayashi
 
PDF
Showdown of the Asserts by Philipp Krenn
JavaDayUA
 
PDF
Works Applications Test - Chinmay Chauhan
Chinmay Chauhan
 
PDF
Java 8 - Nuts and Bold - SFEIR Benelux
yohanbeschi
 
PDF
New and improved: Coming changes to the unittest module
PyCon Italia
 
PDF
Easy REST APIs with Jersey and RestyGWT
David Chandler
 
PDF
Google Guava
Dmitry Buzdin
 
PDF
Why Kotlin - Apalon Kotlin Sprint Part 1
Kirill Rozov
 
PDF
The Ring programming language version 1.7 book - Part 12 of 196
Mahmoud Samir Fayed
 
PPTX
Turbinando o compilador do Java 8
Marcelo de Castro
 
PPTX
Annotation processing
Florent Champigny
 
PDF
OSGi and Eclipse RCP
Eric Jain
 
PDF
The Ring programming language version 1.6 book - Part 11 of 189
Mahmoud Samir Fayed
 
PDF
STAMP Descartes Presentation
STAMP Project
 
PDF
Java 8: the good, the bad and the ugly (Oracle Code Brussels 2017)
Brian Vermeer
 
TXT
New text document
mirzaaabdulmanan
 
PDF
Stop Making Excuses and Start Testing Your JavaScript
Ryan Anklam
 
Java8 tgtbatu javaone
Brian Vermeer
 
Java(8) The Good, The Bad and the Ugly
Brian Vermeer
 
Showdown of the Asserts by Philipp Krenn
JavaDayUA
 
Works Applications Test - Chinmay Chauhan
Chinmay Chauhan
 
Java 8 - Nuts and Bold - SFEIR Benelux
yohanbeschi
 
New and improved: Coming changes to the unittest module
PyCon Italia
 
Easy REST APIs with Jersey and RestyGWT
David Chandler
 
Google Guava
Dmitry Buzdin
 
Why Kotlin - Apalon Kotlin Sprint Part 1
Kirill Rozov
 
The Ring programming language version 1.7 book - Part 12 of 196
Mahmoud Samir Fayed
 
Turbinando o compilador do Java 8
Marcelo de Castro
 
Annotation processing
Florent Champigny
 
OSGi and Eclipse RCP
Eric Jain
 
The Ring programming language version 1.6 book - Part 11 of 189
Mahmoud Samir Fayed
 
STAMP Descartes Presentation
STAMP Project
 
Java 8: the good, the bad and the ugly (Oracle Code Brussels 2017)
Brian Vermeer
 
New text document
mirzaaabdulmanan
 
Stop Making Excuses and Start Testing Your JavaScript
Ryan Anklam
 
Ad

Viewers also liked (8)

PDF
Λίστα Φαρμάκων OTC στην Ελλάδα
Panagiotis Zarogoulidis
 
PDF
MTX M2M application slides
Jesus Santos
 
PDF
Unit тестирование
Alexander Martyushev
 
PPT
Smu study abroad program
nataliedwilson
 
PPTX
Low Maintanence
Katie Wells
 
PPT
Smu study abroad program complete
nataliedwilson
 
PDF
λίστα Otc
Panagiotis Zarogoulidis
 
PPT
Mass media
AlenaCepigova
 
Λίστα Φαρμάκων OTC στην Ελλάδα
Panagiotis Zarogoulidis
 
MTX M2M application slides
Jesus Santos
 
Unit тестирование
Alexander Martyushev
 
Smu study abroad program
nataliedwilson
 
Low Maintanence
Katie Wells
 
Smu study abroad program complete
nataliedwilson
 
λίστα Otc
Panagiotis Zarogoulidis
 
Mass media
AlenaCepigova
 
Ad

Similar to Tdd (20)

PDF
Please create the appropriate JUnit test cases to thoroughly.pdf
kitty811
 
PDF
I need help creating a parametized JUnit test case for the following.pdf
fonecomp
 
PDF
import static org.junit.Assert.;import java.util.Arrays; import.pdf
sudheerforce
 
PDF
public static ArrayListInteger doArrayListInsertAtMedian(int nu.pdf
arihanthtoysandgifts
 
DOCX
COLLECTION IN JAVA PROGRAMMING LANGUAGES
suryae1988
 
PPTX
Migrating to JUnit 5
Rafael Winterhalter
 
PDF
Sorting Questions (JAVA)See attached classes below.Attached Clas.pdf
akritigallery
 
PDF
Important java programs(collection+file)
Alok Kumar
 
PDF
OrderTest.javapublic class OrderTest {       Get an arra.pdf
akkhan101
 
PPT
3 j unit
kishoregali
 
PDF
package ADTs public interface CollectionADTltTgt .pdf
syedabdul78662
 
PPT
Exception handling
Kapish Joshi
 
PPTX
JUnit 5 - The Next Generation of JUnit - Ted's Tool Time
Ted Vinke
 
PPTX
Nice to meet Kotlin
Jieyi Wu
 
PDF
package singlylinkedlist; public class Node { public String valu.pdf
amazing2001
 
PDF
JUnit
Li-Wei Cheng
 
DOC
Awt
Swarup Saha
 
PDF
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
freddysarabia1
 
DOCX
Its Concept of Collection _JAVA_Collection2.docx
sonalipatil225940
 
DOCX
EmptyCollectionException-java -- - Represents the situation in which.docx
BlakeSGMHemmingss
 
Please create the appropriate JUnit test cases to thoroughly.pdf
kitty811
 
I need help creating a parametized JUnit test case for the following.pdf
fonecomp
 
import static org.junit.Assert.;import java.util.Arrays; import.pdf
sudheerforce
 
public static ArrayListInteger doArrayListInsertAtMedian(int nu.pdf
arihanthtoysandgifts
 
COLLECTION IN JAVA PROGRAMMING LANGUAGES
suryae1988
 
Migrating to JUnit 5
Rafael Winterhalter
 
Sorting Questions (JAVA)See attached classes below.Attached Clas.pdf
akritigallery
 
Important java programs(collection+file)
Alok Kumar
 
OrderTest.javapublic class OrderTest {       Get an arra.pdf
akkhan101
 
3 j unit
kishoregali
 
package ADTs public interface CollectionADTltTgt .pdf
syedabdul78662
 
Exception handling
Kapish Joshi
 
JUnit 5 - The Next Generation of JUnit - Ted's Tool Time
Ted Vinke
 
Nice to meet Kotlin
Jieyi Wu
 
package singlylinkedlist; public class Node { public String valu.pdf
amazing2001
 
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
freddysarabia1
 
Its Concept of Collection _JAVA_Collection2.docx
sonalipatil225940
 
EmptyCollectionException-java -- - Represents the situation in which.docx
BlakeSGMHemmingss
 

Recently uploaded (20)

PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
PDF
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
PDF
Doc9.....................................
SofiaCollazos
 
PDF
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
PDF
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
PDF
Brief History of Internet - Early Days of Internet
sutharharshit158
 
PDF
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
PPTX
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
PDF
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
 
PPTX
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
PDF
AI-Cloud-Business-Management-Platforms-The-Key-to-Efficiency-Growth.pdf
Artjoker Software Development Company
 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
PDF
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
PDF
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
PPTX
Simple and concise overview about Quantum computing..pptx
mughal641
 
PPTX
Agile Chennai 18-19 July 2025 | Emerging patterns in Agentic AI by Bharani Su...
AgileNetwork
 
PDF
The Future of Artificial Intelligence (AI)
Mukul
 
PDF
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
PPTX
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
Doc9.....................................
SofiaCollazos
 
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
Brief History of Internet - Early Days of Internet
sutharharshit158
 
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
 
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
AI-Cloud-Business-Management-Platforms-The-Key-to-Efficiency-Growth.pdf
Artjoker Software Development Company
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
Simple and concise overview about Quantum computing..pptx
mughal641
 
Agile Chennai 18-19 July 2025 | Emerging patterns in Agentic AI by Bharani Su...
AgileNetwork
 
The Future of Artificial Intelligence (AI)
Mukul
 
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 

Tdd

  • 1. Тесты — хорошо :) Когда писать тесты? Сколько писать тестов?
  • 3. 1.You may not write production code until you have written a failing unit test. 2.You may not write more of a unit test than is sufficient to fail, and not compiling is failing. 3.You may not write more production code than is sufficient to pass the currently failing test. Три закона TDD «Clean Code», Robert C.Martin
  • 4. Prime Factors Kata Object Mentor, Inc. www.objectmentor.com blog.objectmentor.com fitnesse.org www.junit.org Copyright © 2005 by Object Mentor, Inc All copies must retain this page unchanged.
  • 5. 1 package primeFactors; import junit.framework.TestCase; public class PrimeFactorsTest extends TestCase { public void testOne() throws Exception { assertEquals(list(),PrimeFactors.generate(1)); } }
  • 6. 1 package primeFactors; import junit.framework.TestCase; import java.util.List; public class PrimeFactorsTest extends TestCase { public void testOne() throws Exception { assertEquals(list(),PrimeFactors.generate(1)); } private List<Integer> list() { return null; } }
  • 7. 1 package primeFactors; package primeFactors; import junit.framework.TestCase; public class PrimeFactors { } import java.util.List; public class PrimeFactorsTest extends TestCase { public void testOne() throws Exception { assertEquals(list(),PrimeFactors.generate(1)); } private List<Integer> list() { return null; } }
  • 8. 1 package primeFactors; package primeFactors; import junit.framework.TestCase; import java.util.*; import java.util.List; public class PrimeFactors { public static List<Integer> generate(int n) { public class PrimeFactorsTest extends TestCase { return new ArrayList<Integer>(); public void testOne() throws Exception { } assertEquals(list(),PrimeFactors.generate(1)); } } private List<Integer> list() { return null; } }
  • 9. 1 package primeFactors; package primeFactors; import junit.framework.TestCase; import java.util.*; import java.util.*; public class PrimeFactors { public static List<Integer> generate(int n) { public class PrimeFactorsTest extends TestCase { return new ArrayList<Integer>(); public void testOne() throws Exception { } assertEquals(list(),PrimeFactors.generate(1)); } } private List<Integer> list() { return new ArrayList<Integer>(); } }
  • 10. 1 package primeFactors; package primeFactors; import junit.framework.TestCase; import java.util.*; import java.util.*; public class PrimeFactors { public static List<Integer> generate(int n) { public class PrimeFactorsTest extends TestCase { return new ArrayList<Integer>(); private List<Integer> list() { } return new ArrayList<Integer>(); } } public void testOne() throws Exception { assertEquals(list(),PrimeFactors.generate(1)); } }
  • 11. 1 2 package primeFactors; package primeFactors; import junit.framework.TestCase; import java.util.*; import java.util.*; public class PrimeFactors { public static List<Integer> generate(int n) { public class PrimeFactorsTest extends TestCase { return new ArrayList<Integer>(); private List<Integer> list() { } return new ArrayList<Integer>(); } } public void testOne() throws Exception { assertEquals(list(),PrimeFactors.generate(1)); } public void testTwo() throws Exception { assertEquals(list(2),PrimeFactors.generate(2)); } }
  • 12. 1 2 package primeFactors; package primeFactors; import junit.framework.TestCase; import java.util.*; import java.util.*; public class PrimeFactors { public static List<Integer> generate(int n) { public class PrimeFactorsTest extends TestCase { return new ArrayList<Integer>(); private List<Integer> list(int... ints) { varargs } List<Integer> list = new ArrayList<Integer>(); } for (int i : ints) list.add(i); return list; } public void testOne() throws Exception { assertEquals(list(),PrimeFactors.generate(1)); } public void testTwo() throws Exception { assertEquals(list(2),PrimeFactors.generate(2)); } }
  • 13. 1 2 package primeFactors; package primeFactors; import junit.framework.TestCase; import java.util.*; import java.util.*; public class PrimeFactors { public static List<Integer> generate(int n) { public class PrimeFactorsTest extends TestCase { List<Integer> primes = new ArrayList<Integer>(); private List<Integer> list(int... ints) { if (n > 1) { List<Integer> list = new ArrayList<Integer>(); primes.add(2); for (int i : ints) } list.add(i); return primes; return list; } } } public void testOne() throws Exception { assertEquals(list(),PrimeFactors.generate(1)); } public void testTwo() throws Exception { assertEquals(list(2),PrimeFactors.generate(2)); } }
  • 14. 1 2 package primeFactors; package primeFactors; import static primeFactors.PrimeFactors.generate; import java.util.*; import junit.framework.TestCase; import java.util.*; public class PrimeFactors { public static List<Integer> generate(int n) { public class PrimeFactorsTest extends TestCase { List<Integer> primes = new ArrayList<Integer>(); private List<Integer> list(int... ints) { if (n > 1) { List<Integer> list = new ArrayList<Integer>(); primes.add(2); for (int i : ints) } list.add(i); return primes; return list; } } } public void testOne() throws Exception { assertEquals(list(),generate(1)); } public void testTwo() throws Exception { assertEquals(list(2),generate(2)); } }
  • 15. 1 2 3 package primeFactors; package primeFactors; import static primeFactors.PrimeFactors.generate; import java.util.*; import junit.framework.TestCase; import java.util.*; public class PrimeFactors { public static List<Integer> generate(int n) { public class PrimeFactorsTest extends TestCase { List<Integer> primes = new ArrayList<Integer>(); private List<Integer> list(int... ints) { if (n > 1) { List<Integer> list = new ArrayList<Integer>(); primes.add(2); for (int i : ints) } list.add(i); return primes; return list; } } } public void testOne() throws Exception { assertEquals(list(),generate(1)); } public void testTwo() throws Exception { assertEquals(list(2),generate(2)); } public void testThree() throws Exception { assertEquals(list(3),generate(3)); } }
  • 16. 1 2 3 package primeFactors; package primeFactors; import static primeFactors.PrimeFactors.generate; import java.util.*; import junit.framework.TestCase; import java.util.*; public class PrimeFactors { public static List<Integer> generate(int n) { public class PrimeFactorsTest extends TestCase { List<Integer> primes = new ArrayList<Integer>(); private List<Integer> list(int... ints) { if (n > 1) { List<Integer> list = new ArrayList<Integer>(); primes.add(n); for (int i : ints) } list.add(i); return primes; return list; } } } public void testOne() throws Exception { assertEquals(list(),generate(1)); } public void testTwo() throws Exception { assertEquals(list(2),generate(2)); } public void testThree() throws Exception { assertEquals(list(3),generate(3)); } }
  • 17. 1 2 3 4 package primeFactors; package primeFactors; import static primeFactors.PrimeFactors.generate; import java.util.*; import junit.framework.TestCase; import java.util.*; public class PrimeFactors { public static List<Integer> generate(int n) { public class PrimeFactorsTest extends TestCase { List<Integer> primes = new ArrayList<Integer>(); private List<Integer> list(int... ints) { if (n > 1) { List<Integer> list = new ArrayList<Integer>(); primes.add(n); for (int i : ints) } list.add(i); return primes; return list; } } } public void testOne() throws Exception { assertEquals(list(),generate(1)); } public void testTwo() throws Exception { assertEquals(list(2),generate(2)); } public void testThree() throws Exception { assertEquals(list(3),generate(3)); } public void testFour() throws Exception { assertEquals(list(2,2),generate(4)); } }
  • 18. 1 2 3 4 package primeFactors; package primeFactors; import static primeFactors.PrimeFactors.generate; import java.util.*; import junit.framework.TestCase; import java.util.*; public class PrimeFactors { public static List<Integer> generate(int n) { public class PrimeFactorsTest extends TestCase { List<Integer> primes = new ArrayList<Integer>(); private List<Integer> list(int... ints) { if (n > 1) { List<Integer> list = new ArrayList<Integer>(); if (n%2 == 0) { for (int i : ints) primes.add(2); list.add(i); n /= 2; return list; } } if (n > 1) primes.add(n); public void testOne() throws Exception { } assertEquals(list(),generate(1)); return primes; } } } public void testTwo() throws Exception { assertEquals(list(2),generate(2)); } public void testThree() throws Exception { assertEquals(list(3),generate(3)); } public void testFour() throws Exception { assertEquals(list(2,2),generate(4)); } }
  • 19. 1 2 3 4 5 package primeFactors; package primeFactors; import static primeFactors.PrimeFactors.generate; import java.util.*; import junit.framework.TestCase; import java.util.*; public class PrimeFactors { public static List<Integer> generate(int n) { public class PrimeFactorsTest extends TestCase { List<Integer> primes = new ArrayList<Integer>(); private List<Integer> list(int... ints) { if (n > 1) { List<Integer> list = new ArrayList<Integer>(); if (n%2 == 0) { for (int i : ints) primes.add(2); list.add(i); n /= 2; return list; } } if (n > 1) primes.add(n); public void testOne() throws Exception { } assertEquals(list(),generate(1)); return primes; } } } public void testTwo() throws Exception { assertEquals(list(2),generate(2)); } public void testThree() throws Exception { assertEquals(list(3),generate(3)); } public void testFour() throws Exception { assertEquals(list(2,2),generate(4)); } public void testFive() throws Exception { assertEquals(list(2,3),generate(6)); } }
  • 20. 1 2 3 4 5 6 package primeFactors; package primeFactors; import static primeFactors.PrimeFactors.generate; import java.util.*; import junit.framework.TestCase; import java.util.*; public class PrimeFactors { public static List<Integer> generate(int n) { public class PrimeFactorsTest extends TestCase { List<Integer> primes = new ArrayList<Integer>(); private List<Integer> list(int... ints) { if (n > 1) { List<Integer> list = new ArrayList<Integer>(); if (n%2 == 0) { for (int i : ints) primes.add(2); list.add(i); n /= 2; return list; } } if (n > 1) primes.add(n); public void testOne() throws Exception { } assertEquals(list(),generate(1)); return primes; } } } public void testTwo() throws Exception { assertEquals(list(2),generate(2)); } public void testThree() throws Exception { assertEquals(list(3),generate(3)); } public void testFour() throws Exception { assertEquals(list(2,2),generate(4)); } public void testFive() throws Exception { assertEquals(list(2,3),generate(6)); } public void testSix() throws Exception { assertEquals(list(2,2,2),generate(8)); } }
  • 21. 1 2 3 4 5 6 package primeFactors; package primeFactors; import static primeFactors.PrimeFactors.generate; import java.util.*; import junit.framework.TestCase; import java.util.*; public class PrimeFactors { public static List<Integer> generate(int n) { public class PrimeFactorsTest extends TestCase { List<Integer> primes = new ArrayList<Integer>(); private List<Integer> list(int... ints) { if (n > 1) { List<Integer> list = new ArrayList<Integer>(); while (n%2 == 0) { for (int i : ints) primes.add(2); list.add(i); n /= 2; ! ! ! return list; } } if (n > 1) primes.add(n); public void testOne() throws Exception { } assertEquals(list(),generate(1)); return primes; } } } public void testTwo() throws Exception { assertEquals(list(2),generate(2)); } public void testThree() throws Exception { assertEquals(list(3),generate(3)); } public void testFour() throws Exception { assertEquals(list(2,2),generate(4)); } public void testFive() throws Exception { assertEquals(list(2,3),generate(6)); } public void testSix() throws Exception { assertEquals(list(2,2,2),generate(8)); } }
  • 22. 1 2 3 4 5 6 7 package primeFactors; import static primeFactors.PrimeFactors.generate; import junit.framework.TestCase; import java.util.*; package primeFactors; public class PrimeFactorsTest extends TestCase { import java.util.*; private List<Integer> list(int... ints) { List<Integer> list = new ArrayList<Integer>(); public class PrimeFactors { for (int i : ints) public static List<Integer> generate(int n) { list.add(i); List<Integer> primes = new ArrayList<Integer>(); return list; if (n > 1) { } while (n%2 == 0) { primes.add(2); public void testOne() throws Exception { n /= 2; assertEquals(list(),generate(1)); } } if (n > 1) primes.add(n); public void testTwo() throws Exception { } assertEquals(list(2),generate(2)); return primes; } } } public void testThree() throws Exception { assertEquals(list(3),generate(3)); } public void testFour() throws Exception { assertEquals(list(2,2),generate(4)); } public void testFive() throws Exception { assertEquals(list(2,3),generate(6)); } public void testSix() throws Exception { assertEquals(list(2,2,2),generate(8)); } public void testSeven() throws Exception { assertEquals(list(3,3),generate(9)); } }
  • 23. 1 2 3 4 5 6 7 package primeFactors; import static primeFactors.PrimeFactors.generate; import junit.framework.TestCase; import java.util.*; package primeFactors; public class PrimeFactorsTest extends TestCase { import java.util.*; private List<Integer> list(int... ints) { List<Integer> list = new ArrayList<Integer>(); public class PrimeFactors { for (int i : ints) public static List<Integer> generate(int n) { list.add(i); List<Integer> primes = new ArrayList<Integer>(); return list; if (n > 1) { } int candidate = 2; while (n%candidate == 0) { public void testOne() throws Exception { primes.add(candidate); assertEquals(list(),generate(1)); n /= candidate; } } if (n > 1) public void testTwo() throws Exception { primes.add(n); assertEquals(list(2),generate(2)); } } return primes; } public void testThree() throws Exception { assertEquals(list(3),generate(3)); } } public void testFour() throws Exception { assertEquals(list(2,2),generate(4)); } public void testFive() throws Exception { assertEquals(list(2,3),generate(6)); } public void testSix() throws Exception { assertEquals(list(2,2,2),generate(8)); } public void testSeven() throws Exception { assertEquals(list(3,3),generate(9)); } }
  • 24. 1 2 3 4 5 6 7 package primeFactors; import static primeFactors.PrimeFactors.generate; import junit.framework.TestCase; import java.util.*; package primeFactors; public class PrimeFactorsTest extends TestCase { import java.util.*; private List<Integer> list(int... ints) { List<Integer> list = new ArrayList<Integer>(); public class PrimeFactors { for (int i : ints) public static List<Integer> generate(int n) { list.add(i); List<Integer> primes = new ArrayList<Integer>(); return list; if (n > 1) { } int candidate = 2; while (n % candidate == 0) { public void testOne() throws Exception { primes.add(candidate); assertEquals(list(),generate(1)); n /= candidate; } } } public void testTwo() throws Exception { if (n > 1) assertEquals(list(2),generate(2)); primes.add(n); } return primes; } public void testThree() throws Exception { assertEquals(list(3),generate(3)); } } public void testFour() throws Exception { assertEquals(list(2,2),generate(4)); } public void testFive() throws Exception { assertEquals(list(2,3),generate(6)); } public void testSix() throws Exception { assertEquals(list(2,2,2),generate(8)); } public void testSeven() throws Exception { assertEquals(list(3,3),generate(9)); } }
  • 25. 1 2 3 4 5 6 7 package primeFactors; import static primeFactors.PrimeFactors.generate; import junit.framework.TestCase; import java.util.*; package primeFactors; public class PrimeFactorsTest extends TestCase { import java.util.*; private List<Integer> list(int... ints) { List<Integer> list = new ArrayList<Integer>(); public class PrimeFactors { for (int i : ints) public static List<Integer> generate(int n) { list.add(i); List<Integer> primes = new ArrayList<Integer>(); return list; int candidate = 2; } if (n > 1) { while (n % candidate == 0) { public void testOne() throws Exception { primes.add(candidate); assertEquals(list(),generate(1)); n /= candidate; } } } public void testTwo() throws Exception { if (n > 1) assertEquals(list(2),generate(2)); primes.add(n); } return primes; } public void testThree() throws Exception { assertEquals(list(3),generate(3)); } } public void testFour() throws Exception { assertEquals(list(2,2),generate(4)); } public void testFive() throws Exception { assertEquals(list(2,3),generate(6)); } public void testSix() throws Exception { assertEquals(list(2,2,2),generate(8)); } public void testSeven() throws Exception { assertEquals(list(3,3),generate(9)); } }
  • 26. 1 2 3 4 5 6 7 package primeFactors; import static primeFactors.PrimeFactors.generate; import junit.framework.TestCase; import java.util.*; package primeFactors; public class PrimeFactorsTest extends TestCase { import java.util.*; private List<Integer> list(int... ints) { List<Integer> list = new ArrayList<Integer>(); public class PrimeFactors { for (int i : ints) public static List<Integer> generate(int n) { list.add(i); List<Integer> primes = new ArrayList<Integer>(); return list; int candidate = 2; } if (n > 1) { while (n % candidate == 0) { public void testOne() throws Exception { primes.add(candidate); assertEquals(list(),generate(1)); n /= candidate; } } } public void testTwo() throws Exception { if (n > 1) assertEquals(list(2),generate(2)); primes.add(n); } return primes; } public void testThree() throws Exception { assertEquals(list(3),generate(3)); } } public void testFour() throws Exception { assertEquals(list(2,2),generate(4)); } public void testFive() throws Exception { assertEquals(list(2,3),generate(6)); } public void testSix() throws Exception { assertEquals(list(2,2,2),generate(8)); } public void testSeven() throws Exception { assertEquals(list(3,3),generate(9)); } }
  • 27. 1 2 3 4 5 6 7 package primeFactors; import static primeFactors.PrimeFactors.generate; import junit.framework.TestCase; import java.util.*; package primeFactors; public class PrimeFactorsTest extends TestCase { import java.util.*; private List<Integer> list(int... ints) { List<Integer> list = new ArrayList<Integer>(); public class PrimeFactors { for (int i : ints) public static List<Integer> generate(int n) { list.add(i); List<Integer> primes = new ArrayList<Integer>(); return list; int candidate = 2; } while (n > 1) { while (n % candidate == 0) { ! ! ! public void testOne() throws Exception { primes.add(candidate); assertEquals(list(),generate(1)); n /= candidate; } } candidate++; public void testTwo() throws Exception { } assertEquals(list(2),generate(2)); if (n > 1) } primes.add(n); return primes; public void testThree() throws Exception { assertEquals(list(3),generate(3)); } } } public void testFour() throws Exception { assertEquals(list(2,2),generate(4)); } public void testFive() throws Exception { assertEquals(list(2,3),generate(6)); } public void testSix() throws Exception { assertEquals(list(2,2,2),generate(8)); } public void testSeven() throws Exception { assertEquals(list(3,3),generate(9)); } }
  • 28. 1 2 3 4 5 6 7 package primeFactors; import static primeFactors.PrimeFactors.generate; import junit.framework.TestCase; import java.util.*; package primeFactors; public class PrimeFactorsTest extends TestCase { import java.util.*; private List<Integer> list(int... ints) { List<Integer> list = new ArrayList<Integer>(); public class PrimeFactors { for (int i : ints) public static List<Integer> generate(int n) { list.add(i); List<Integer> primes = new ArrayList<Integer>(); return list; int candidate = 2; } while (n > 1) { while (n % candidate == 0) { public void testOne() throws Exception { primes.add(candidate); assertEquals(list(),generate(1)); n /= candidate; } } candidate++; public void testTwo() throws Exception { } assertEquals(list(2),generate(2)); return primes; } } } public void testThree() throws Exception { assertEquals(list(3),generate(3)); } public void testFour() throws Exception { assertEquals(list(2,2),generate(4)); } public void testFive() throws Exception { assertEquals(list(2,3),generate(6)); } public void testSix() throws Exception { assertEquals(list(2,2,2),generate(8)); } public void testSeven() throws Exception { assertEquals(list(3,3),generate(9)); } }
  • 29. 1 2 3 4 5 6 7 package primeFactors; import static primeFactors.PrimeFactors.generate; import junit.framework.TestCase; import java.util.*; package primeFactors; public class PrimeFactorsTest extends TestCase { import java.util.*; private List<Integer> list(int... ints) { List<Integer> list = new ArrayList<Integer>(); public class PrimeFactors { for (int i : ints) public static List<Integer> generate(int n) { list.add(i); List<Integer> primes = new ArrayList<Integer>(); return list; int candidate = 2; } while (n > 1) { for (; n%candidate == 0; n/=candidate) public void testOne() throws Exception { primes.add(candidate); assertEquals(list(),generate(1)); } candidate++; } public void testTwo() throws Exception { return primes; assertEquals(list(2),generate(2)); } } } public void testThree() throws Exception { assertEquals(list(3),generate(3)); } public void testFour() throws Exception { assertEquals(list(2,2),generate(4)); } public void testFive() throws Exception { assertEquals(list(2,3),generate(6)); } public void testSix() throws Exception { assertEquals(list(2,2,2),generate(8)); } public void testSeven() throws Exception { assertEquals(list(3,3),generate(9)); } }
  • 30. 1 2 3 4 5 6 7 package primeFactors; import static primeFactors.PrimeFactors.generate; import junit.framework.TestCase; import java.util.*; package primeFactors; public class PrimeFactorsTest extends TestCase { import java.util.*; private List<Integer> list(int... ints) { List<Integer> list = new ArrayList<Integer>(); public class PrimeFactors { for (int i : ints) public static List<Integer> generate(int n) { list.add(i); List<Integer> primes = new ArrayList<Integer>(); return list; } for (int candidate = 2; n > 1; candidate++) for (; n%candidate == 0; n/=candidate) public void testOne() throws Exception { primes.add(candidate); assertEquals(list(),generate(1)); } return primes; } public void testTwo() throws Exception { } assertEquals(list(2),generate(2)); } public void testThree() throws Exception { assertEquals(list(3),generate(3)); } public void testFour() throws Exception { assertEquals(list(2,2),generate(4)); } public void testFive() throws Exception { assertEquals(list(2,3),generate(6)); } public void testSix() throws Exception { assertEquals(list(2,2,2),generate(8)); } public void testSeven() throws Exception { assertEquals(list(3,3),generate(9)); } }
  • 31. 1 2 3 4 5 6 7 package primeFactors; import static primeFactors.PrimeFactors.generate; import junit.framework.TestCase; import java.util.*; package primeFactors; public class PrimeFactorsTest extends TestCase { import java.util.*; private List<Integer> list(int... ints) { List<Integer> list = new ArrayList<Integer>(); public class PrimeFactors { for (int i : ints) public static List<Integer> generate(int n) { list.add(i); List<Integer> primes = new ArrayList<Integer>(); return list; } for (int candidate = 2; n > 1; candidate++) for (; n%candidate == 0; n/=candidate) public void testOne() throws Exception { primes.add(candidate); assertEquals(list(),generate(1)); } return primes; } public void testTwo() throws Exception { } assertEquals(list(2),generate(2)); } public void testThree() throws Exception { assertEquals(list(3),generate(3)); } public void testFour() throws Exception { } assertEquals(list(2,2),generate(4)); public void testFive() throws Exception { 3 строчки кода!!! assertEquals(list(2,3),generate(6)); } public void testSix() throws Exception { assertEquals(list(2,2,2),generate(8)); } public void testSeven() throws Exception { assertEquals(list(3,3),generate(9)); } }