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

Сколько писать тестов?
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

What's hot

Java8 tgtbatu javaone
Java8 tgtbatu javaoneJava8 tgtbatu javaone
Java8 tgtbatu javaoneBrian Vermeer
 
Java(8) The Good, The Bad and the Ugly
Java(8) The Good, The Bad and the UglyJava(8) The Good, The Bad and the Ugly
Java(8) The Good, The Bad and the UglyBrian Vermeer
 
Showdown of the Asserts by Philipp Krenn
Showdown of the Asserts by Philipp KrennShowdown of the Asserts by Philipp Krenn
Showdown of the Asserts by Philipp KrennJavaDayUA
 
Works Applications Test - Chinmay Chauhan
Works Applications Test - Chinmay ChauhanWorks Applications Test - Chinmay Chauhan
Works Applications Test - Chinmay ChauhanChinmay Chauhan
 
Java 8 - Nuts and Bold - SFEIR Benelux
Java 8 - Nuts and Bold - SFEIR BeneluxJava 8 - Nuts and Bold - SFEIR Benelux
Java 8 - Nuts and Bold - SFEIR Beneluxyohanbeschi
 
New and improved: Coming changes to the unittest module
 	 New and improved: Coming changes to the unittest module 	 New and improved: Coming changes to the unittest module
New and improved: Coming changes to the unittest modulePyCon Italia
 
Easy REST APIs with Jersey and RestyGWT
Easy REST APIs with Jersey and RestyGWTEasy REST APIs with Jersey and RestyGWT
Easy REST APIs with Jersey and RestyGWTDavid Chandler
 
Why Kotlin - Apalon Kotlin Sprint Part 1
Why Kotlin - Apalon Kotlin Sprint Part 1Why Kotlin - Apalon Kotlin Sprint Part 1
Why Kotlin - Apalon Kotlin Sprint Part 1Kirill Rozov
 
The Ring programming language version 1.7 book - Part 12 of 196
The Ring programming language version 1.7 book - Part 12 of 196The Ring programming language version 1.7 book - Part 12 of 196
The Ring programming language version 1.7 book - Part 12 of 196Mahmoud Samir Fayed
 
Turbinando o compilador do Java 8
Turbinando o compilador do Java 8Turbinando o compilador do Java 8
Turbinando o compilador do Java 8Marcelo de Castro
 
OSGi and Eclipse RCP
OSGi and Eclipse RCPOSGi and Eclipse RCP
OSGi and Eclipse RCPEric Jain
 
The Ring programming language version 1.6 book - Part 11 of 189
The Ring programming language version 1.6 book - Part 11 of 189The Ring programming language version 1.6 book - Part 11 of 189
The Ring programming language version 1.6 book - Part 11 of 189Mahmoud Samir Fayed
 
STAMP Descartes Presentation
STAMP Descartes PresentationSTAMP Descartes Presentation
STAMP Descartes PresentationSTAMP Project
 
Java 8: the good, the bad and the ugly (Oracle Code Brussels 2017)
Java 8: the good, the bad and the ugly (Oracle Code Brussels 2017)Java 8: the good, the bad and the ugly (Oracle Code Brussels 2017)
Java 8: the good, the bad and the ugly (Oracle Code Brussels 2017)Brian Vermeer
 
Stop Making Excuses and Start Testing Your JavaScript
Stop Making Excuses and Start Testing Your JavaScriptStop Making Excuses and Start Testing Your JavaScript
Stop Making Excuses and Start Testing Your JavaScriptRyan Anklam
 

What's hot (20)

Java8 tgtbatu javaone
Java8 tgtbatu javaoneJava8 tgtbatu javaone
Java8 tgtbatu javaone
 
Java(8) The Good, The Bad and the Ugly
Java(8) The Good, The Bad and the UglyJava(8) The Good, The Bad and the Ugly
Java(8) The Good, The Bad and the Ugly
 
Guice2.0
Guice2.0Guice2.0
Guice2.0
 
Showdown of the Asserts by Philipp Krenn
Showdown of the Asserts by Philipp KrennShowdown of the Asserts by Philipp Krenn
Showdown of the Asserts by Philipp Krenn
 
Works Applications Test - Chinmay Chauhan
Works Applications Test - Chinmay ChauhanWorks Applications Test - Chinmay Chauhan
Works Applications Test - Chinmay Chauhan
 
Java 8 - Nuts and Bold - SFEIR Benelux
Java 8 - Nuts and Bold - SFEIR BeneluxJava 8 - Nuts and Bold - SFEIR Benelux
Java 8 - Nuts and Bold - SFEIR Benelux
 
New and improved: Coming changes to the unittest module
 	 New and improved: Coming changes to the unittest module 	 New and improved: Coming changes to the unittest module
New and improved: Coming changes to the unittest module
 
7.Spring DI_2
7.Spring DI_27.Spring DI_2
7.Spring DI_2
 
Easy REST APIs with Jersey and RestyGWT
Easy REST APIs with Jersey and RestyGWTEasy REST APIs with Jersey and RestyGWT
Easy REST APIs with Jersey and RestyGWT
 
Google Guava
Google GuavaGoogle Guava
Google Guava
 
Why Kotlin - Apalon Kotlin Sprint Part 1
Why Kotlin - Apalon Kotlin Sprint Part 1Why Kotlin - Apalon Kotlin Sprint Part 1
Why Kotlin - Apalon Kotlin Sprint Part 1
 
The Ring programming language version 1.7 book - Part 12 of 196
The Ring programming language version 1.7 book - Part 12 of 196The Ring programming language version 1.7 book - Part 12 of 196
The Ring programming language version 1.7 book - Part 12 of 196
 
Turbinando o compilador do Java 8
Turbinando o compilador do Java 8Turbinando o compilador do Java 8
Turbinando o compilador do Java 8
 
Annotation processing
Annotation processingAnnotation processing
Annotation processing
 
OSGi and Eclipse RCP
OSGi and Eclipse RCPOSGi and Eclipse RCP
OSGi and Eclipse RCP
 
The Ring programming language version 1.6 book - Part 11 of 189
The Ring programming language version 1.6 book - Part 11 of 189The Ring programming language version 1.6 book - Part 11 of 189
The Ring programming language version 1.6 book - Part 11 of 189
 
STAMP Descartes Presentation
STAMP Descartes PresentationSTAMP Descartes Presentation
STAMP Descartes Presentation
 
Java 8: the good, the bad and the ugly (Oracle Code Brussels 2017)
Java 8: the good, the bad and the ugly (Oracle Code Brussels 2017)Java 8: the good, the bad and the ugly (Oracle Code Brussels 2017)
Java 8: the good, the bad and the ugly (Oracle Code Brussels 2017)
 
New text document
New text documentNew text document
New text document
 
Stop Making Excuses and Start Testing Your JavaScript
Stop Making Excuses and Start Testing Your JavaScriptStop Making Excuses and Start Testing Your JavaScript
Stop Making Excuses and Start Testing Your JavaScript
 

Viewers also liked

Viewers also liked (8)

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

Similar to Tdd

Please create the appropriate JUnit test cases to thoroughly.pdf
Please create the appropriate JUnit test cases to thoroughly.pdfPlease create the appropriate JUnit test cases to thoroughly.pdf
Please create the appropriate JUnit test cases to thoroughly.pdfkitty811
 
I need help creating a parametized JUnit test case for the following.pdf
I need help creating a parametized JUnit test case for the following.pdfI need help creating a parametized JUnit test case for the following.pdf
I need help creating a parametized JUnit test case for the following.pdffonecomp
 
import static org.junit.Assert.;import java.util.Arrays; import.pdf
import static org.junit.Assert.;import java.util.Arrays; import.pdfimport static org.junit.Assert.;import java.util.Arrays; import.pdf
import static org.junit.Assert.;import java.util.Arrays; import.pdfsudheerforce
 
public static ArrayListInteger doArrayListInsertAtMedian(int nu.pdf
public static ArrayListInteger doArrayListInsertAtMedian(int nu.pdfpublic static ArrayListInteger doArrayListInsertAtMedian(int nu.pdf
public static ArrayListInteger doArrayListInsertAtMedian(int nu.pdfarihanthtoysandgifts
 
Sorting Questions (JAVA)See attached classes below.Attached Clas.pdf
Sorting Questions (JAVA)See attached classes below.Attached Clas.pdfSorting Questions (JAVA)See attached classes below.Attached Clas.pdf
Sorting Questions (JAVA)See attached classes below.Attached Clas.pdfakritigallery
 
Important java programs(collection+file)
Important java programs(collection+file)Important java programs(collection+file)
Important java programs(collection+file)Alok Kumar
 
OrderTest.javapublic class OrderTest {       Get an arra.pdf
OrderTest.javapublic class OrderTest {         Get an arra.pdfOrderTest.javapublic class OrderTest {         Get an arra.pdf
OrderTest.javapublic class OrderTest {       Get an arra.pdfakkhan101
 
package ADTs public interface CollectionADTltTgt .pdf
package ADTs public interface CollectionADTltTgt      .pdfpackage ADTs public interface CollectionADTltTgt      .pdf
package ADTs public interface CollectionADTltTgt .pdfsyedabdul78662
 
Exception handling
Exception handlingException handling
Exception handlingKapish Joshi
 
JUnit 5 - The Next Generation of JUnit - Ted's Tool Time
JUnit 5 - The Next Generation of JUnit - Ted's Tool TimeJUnit 5 - The Next Generation of JUnit - Ted's Tool Time
JUnit 5 - The Next Generation of JUnit - Ted's Tool TimeTed Vinke
 
Nice to meet Kotlin
Nice to meet KotlinNice to meet Kotlin
Nice to meet KotlinJieyi Wu
 
package singlylinkedlist; public class Node { public String valu.pdf
package singlylinkedlist; public class Node { public String valu.pdfpackage singlylinkedlist; public class Node { public String valu.pdf
package singlylinkedlist; public class Node { public String valu.pdfamazing2001
 
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdfLabprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdffreddysarabia1
 
EmptyCollectionException-java -- - Represents the situation in which.docx
EmptyCollectionException-java --  - Represents the situation in which.docxEmptyCollectionException-java --  - Represents the situation in which.docx
EmptyCollectionException-java -- - Represents the situation in which.docxBlakeSGMHemmingss
 

Similar to Tdd (20)

Please create the appropriate JUnit test cases to thoroughly.pdf
Please create the appropriate JUnit test cases to thoroughly.pdfPlease create the appropriate JUnit test cases to thoroughly.pdf
Please create the appropriate JUnit test cases to thoroughly.pdf
 
I need help creating a parametized JUnit test case for the following.pdf
I need help creating a parametized JUnit test case for the following.pdfI need help creating a parametized JUnit test case for the following.pdf
I need help creating a parametized JUnit test case for the following.pdf
 
import static org.junit.Assert.;import java.util.Arrays; import.pdf
import static org.junit.Assert.;import java.util.Arrays; import.pdfimport static org.junit.Assert.;import java.util.Arrays; import.pdf
import static org.junit.Assert.;import java.util.Arrays; import.pdf
 
public static ArrayListInteger doArrayListInsertAtMedian(int nu.pdf
public static ArrayListInteger doArrayListInsertAtMedian(int nu.pdfpublic static ArrayListInteger doArrayListInsertAtMedian(int nu.pdf
public static ArrayListInteger doArrayListInsertAtMedian(int nu.pdf
 
Migrating to JUnit 5
Migrating to JUnit 5Migrating to JUnit 5
Migrating to JUnit 5
 
Sorting Questions (JAVA)See attached classes below.Attached Clas.pdf
Sorting Questions (JAVA)See attached classes below.Attached Clas.pdfSorting Questions (JAVA)See attached classes below.Attached Clas.pdf
Sorting Questions (JAVA)See attached classes below.Attached Clas.pdf
 
Important java programs(collection+file)
Important java programs(collection+file)Important java programs(collection+file)
Important java programs(collection+file)
 
OrderTest.javapublic class OrderTest {       Get an arra.pdf
OrderTest.javapublic class OrderTest {         Get an arra.pdfOrderTest.javapublic class OrderTest {         Get an arra.pdf
OrderTest.javapublic class OrderTest {       Get an arra.pdf
 
3 j unit
3 j unit3 j unit
3 j unit
 
package ADTs public interface CollectionADTltTgt .pdf
package ADTs public interface CollectionADTltTgt      .pdfpackage ADTs public interface CollectionADTltTgt      .pdf
package ADTs public interface CollectionADTltTgt .pdf
 
Exception handling
Exception handlingException handling
Exception handling
 
JUnit 5 - The Next Generation of JUnit - Ted's Tool Time
JUnit 5 - The Next Generation of JUnit - Ted's Tool TimeJUnit 5 - The Next Generation of JUnit - Ted's Tool Time
JUnit 5 - The Next Generation of JUnit - Ted's Tool Time
 
Nice to meet Kotlin
Nice to meet KotlinNice to meet Kotlin
Nice to meet Kotlin
 
package singlylinkedlist; public class Node { public String valu.pdf
package singlylinkedlist; public class Node { public String valu.pdfpackage singlylinkedlist; public class Node { public String valu.pdf
package singlylinkedlist; public class Node { public String valu.pdf
 
JUnit
JUnitJUnit
JUnit
 
Awt
AwtAwt
Awt
 
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdfLabprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
 
EmptyCollectionException-java -- - Represents the situation in which.docx
EmptyCollectionException-java --  - Represents the situation in which.docxEmptyCollectionException-java --  - Represents the situation in which.docx
EmptyCollectionException-java -- - Represents the situation in which.docx
 
JUnit 5
JUnit 5JUnit 5
JUnit 5
 
FunctionalInterfaces
FunctionalInterfacesFunctionalInterfaces
FunctionalInterfaces
 

Recently uploaded

TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 

Recently uploaded (20)

TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 

Tdd

  • 1. Тесты — хорошо :) Когда писать тесты? Сколько писать тестов?
  • 2.
  • 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)); } }