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
PPTX
Junit 5 - Maior e melhor
DOCX
Ejemplo radio
DOCX
XTW_Import
PDF
Art of unit testing: How developer should care about code quality
PDF
T.Y.B.S.CS Advance Java Practicals Sem 5 Mumbai University
PDF
The Ring programming language version 1.10 book - Part 42 of 212
PPTX
Pragmatic unittestingwithj unit
Registro de venta
Junit 5 - Maior e melhor
Ejemplo radio
XTW_Import
Art of unit testing: How developer should care about code quality
T.Y.B.S.CS Advance Java Practicals Sem 5 Mumbai University
The Ring programming language version 1.10 book - Part 42 of 212
Pragmatic unittestingwithj unit

What's hot (20)

PDF
Java8 tgtbatu javaone
PDF
Java(8) The Good, The Bad and the Ugly
PDF
PDF
Showdown of the Asserts by Philipp Krenn
PDF
Works Applications Test - Chinmay Chauhan
PDF
Java 8 - Nuts and Bold - SFEIR Benelux
PDF
New and improved: Coming changes to the unittest module
PDF
Easy REST APIs with Jersey and RestyGWT
PDF
Google Guava
PDF
Why Kotlin - Apalon Kotlin Sprint Part 1
PDF
The Ring programming language version 1.7 book - Part 12 of 196
PPTX
Turbinando o compilador do Java 8
PPTX
Annotation processing
PDF
OSGi and Eclipse RCP
PDF
The Ring programming language version 1.6 book - Part 11 of 189
PDF
STAMP Descartes Presentation
PDF
Java 8: the good, the bad and the ugly (Oracle Code Brussels 2017)
TXT
New text document
PDF
Stop Making Excuses and Start Testing Your JavaScript
Java8 tgtbatu javaone
Java(8) The Good, The Bad and the Ugly
Showdown of the Asserts by Philipp Krenn
Works Applications Test - Chinmay Chauhan
Java 8 - Nuts and Bold - SFEIR Benelux
New and improved: Coming changes to the unittest module
Easy REST APIs with Jersey and RestyGWT
Google Guava
Why Kotlin - Apalon Kotlin Sprint Part 1
The Ring programming language version 1.7 book - Part 12 of 196
Turbinando o compilador do Java 8
Annotation processing
OSGi and Eclipse RCP
The Ring programming language version 1.6 book - Part 11 of 189
STAMP Descartes Presentation
Java 8: the good, the bad and the ugly (Oracle Code Brussels 2017)
New text document
Stop Making Excuses and Start Testing Your JavaScript
Ad

Viewers also liked (8)

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

Recently uploaded (20)

PDF
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
PDF
Enhancing emotion recognition model for a student engagement use case through...
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PPTX
observCloud-Native Containerability and monitoring.pptx
PDF
NewMind AI Weekly Chronicles – August ’25 Week III
PPT
What is a Computer? Input Devices /output devices
PDF
STKI Israel Market Study 2025 version august
PPTX
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
PDF
2021 HotChips TSMC Packaging Technologies for Chiplets and 3D_0819 publish_pu...
PDF
Getting Started with Data Integration: FME Form 101
PDF
Hindi spoken digit analysis for native and non-native speakers
PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PPTX
Tartificialntelligence_presentation.pptx
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
1. Introduction to Computer Programming.pptx
PPTX
O2C Customer Invoices to Receipt V15A.pptx
PDF
Zenith AI: Advanced Artificial Intelligence
PDF
WOOl fibre morphology and structure.pdf for textiles
PPTX
Modernising the Digital Integration Hub
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
Enhancing emotion recognition model for a student engagement use case through...
gpt5_lecture_notes_comprehensive_20250812015547.pdf
observCloud-Native Containerability and monitoring.pptx
NewMind AI Weekly Chronicles – August ’25 Week III
What is a Computer? Input Devices /output devices
STKI Israel Market Study 2025 version august
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
2021 HotChips TSMC Packaging Technologies for Chiplets and 3D_0819 publish_pu...
Getting Started with Data Integration: FME Form 101
Hindi spoken digit analysis for native and non-native speakers
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
Tartificialntelligence_presentation.pptx
Programs and apps: productivity, graphics, security and other tools
1. Introduction to Computer Programming.pptx
O2C Customer Invoices to Receipt V15A.pptx
Zenith AI: Advanced Artificial Intelligence
WOOl fibre morphology and structure.pdf for textiles
Modernising the Digital Integration Hub
Group 1 Presentation -Planning and Decision Making .pptx

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)); } }