SlideShare uma empresa Scribd logo
1 de 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

Mais conteúdo relacionado

Mais procurados

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
 

Mais procurados (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
 

Destaque

Destaque (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
 

Semelhante a 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
 

Semelhante a 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
 

Último

08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 

Último (20)

08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 

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