Advertisement
UberMouse

Untitled

Jun 12th, 2011
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 12.29 KB | None | 0 0
  1. import nz.ubermouse.projecteuler.MathHelpers;
  2. import org.junit.After;
  3. import org.junit.Before;
  4. import org.junit.Test;
  5.  
  6. import static org.junit.Assert.assertEquals;
  7.  
  8. /**
  9.  * Created by IntelliJ IDEA.
  10.  * User: Taylor
  11.  * Date: 6/12/11
  12.  * Time: 11:41 AM
  13.  * Package: PACKAGE_NAME;
  14.  */
  15. public class isPrimeTester
  16. {
  17.  
  18.     static final int[] primes    = {3,
  19.                                     5,
  20.                                     7,
  21.                                     11,
  22.                                     13,
  23.                                     17,
  24.                                     19,
  25.                                     23,
  26.                                     29,
  27.                                     31,
  28.                                     37,
  29.                                     41,
  30.                                     43,
  31.                                     47,
  32.                                     53,
  33.                                     59,
  34.                                     61,
  35.                                     67,
  36.                                     71,
  37.                                     73,
  38.                                     79,
  39.                                     83,
  40.                                     89,
  41.                                     97,
  42.                                     101,
  43.                                     103,
  44.                                     107,
  45.                                     109,
  46.                                     113,
  47.                                     127,
  48.                                     131,
  49.                                     137,
  50.                                     139,
  51.                                     149,
  52.                                     151,
  53.                                     157,
  54.                                     163,
  55.                                     167,
  56.                                     173,
  57.                                     179,
  58.                                     181,
  59.                                     191,
  60.                                     193,
  61.                                     197,
  62.                                     199,
  63.                                     211,
  64.                                     223,
  65.                                     227,
  66.                                     229,
  67.                                     233,
  68.                                     239,
  69.                                     241,
  70.                                     251,
  71.                                     257,
  72.                                     263,
  73.                                     269,
  74.                                     271,
  75.                                     277,
  76.                                     281,
  77.                                     283,
  78.                                     293,
  79.                                     307,
  80.                                     311,
  81.                                     313,
  82.                                     317,
  83.                                     331,
  84.                                     337,
  85.                                     347,
  86.                                     349,
  87.                                     353,
  88.                                     359,
  89.                                     367,
  90.                                     373,
  91.                                     379,
  92.                                     383,
  93.                                     389,
  94.                                     397,
  95.                                     401,
  96.                                     409,
  97.                                     419,
  98.                                     421,
  99.                                     431,
  100.                                     433,
  101.                                     439,
  102.                                     443,
  103.                                     449,
  104.                                     457,
  105.                                     461,
  106.                                     463,
  107.                                     467,
  108.                                     479,
  109.                                     487,
  110.                                     491,
  111.                                     499,
  112.                                     503,
  113.                                     509,
  114.                                     521,
  115.                                     523,
  116.                                     541,
  117.                                     547,
  118.                                     557,
  119.                                     563,
  120.                                     569,
  121.                                     571,
  122.                                     577,
  123.                                     587,
  124.                                     593,
  125.                                     599,
  126.                                     601,
  127.                                     607,
  128.                                     613,
  129.                                     617,
  130.                                     619,
  131.                                     631,
  132.                                     641,
  133.                                     643,
  134.                                     647,
  135.                                     653,
  136.                                     659,
  137.                                     661,
  138.                                     673,
  139.                                     677,
  140.                                     683,
  141.                                     691,
  142.                                     701,
  143.                                     709,
  144.                                     719,
  145.                                     727,
  146.                                     733,
  147.                                     739,
  148.                                     743,
  149.                                     751,
  150.                                     757,
  151.                                     761,
  152.                                     769,
  153.                                     773,
  154.                                     787,
  155.                                     797,
  156.                                     809,
  157.                                     811,
  158.                                     821,
  159.                                     823,
  160.                                     827,
  161.                                     829,
  162.                                     839,
  163.                                     853,
  164.                                     857,
  165.                                     859,
  166.                                     863,
  167.                                     877,
  168.                                     881,
  169.                                     883,
  170.                                     887,
  171.                                     907,
  172.                                     911,
  173.                                     919,
  174.                                     929,
  175.                                     937,
  176.                                     941,
  177.                                     947,
  178.                                     953,
  179.                                     967,
  180.                                     971,
  181.                                     977,
  182.                                     983,
  183.                                     991,
  184.                                     997,
  185.                                     1009,
  186.                                     101,
  187.                                     1019,
  188.                                     1021,
  189.                                     1031,
  190.                                     1033,
  191.                                     1039,
  192.                                     1049,
  193.                                     1051,
  194.                                     1061,
  195.                                     1063,
  196.                                     1069};
  197.     static final int[] nonPrimes = {4,
  198.                                     6,
  199.                                     8,
  200.                                     9,
  201.                                     10,
  202.                                     12,
  203.                                     14,
  204.                                     15,
  205.                                     16,
  206.                                     18,
  207.                                     20,
  208.                                     21,
  209.                                     22,
  210.                                     24,
  211.                                     25,
  212.                                     26,
  213.                                     27,
  214.                                     28,
  215.                                     30,
  216.                                     32,
  217.                                     33,
  218.                                     34,
  219.                                     35,
  220.                                     36,
  221.                                     38,
  222.                                     39,
  223.                                     40,
  224.                                     42,
  225.                                     44,
  226.                                     45,
  227.                                     46,
  228.                                     48,
  229.                                     49,
  230.                                     50,
  231.                                     51,
  232.                                     52,
  233.                                     54,
  234.                                     55,
  235.                                     56,
  236.                                     57,
  237.                                     58,
  238.                                     60,
  239.                                     62,
  240.                                     63,
  241.                                     64,
  242.                                     65,
  243.                                     66,
  244.                                     68,
  245.                                     69,
  246.                                     70,
  247.                                     72,
  248.                                     74,
  249.                                     75,
  250.                                     76,
  251.                                     77,
  252.                                     78,
  253.                                     80,
  254.                                     81,
  255.                                     82,
  256.                                     84,
  257.                                     85,
  258.                                     86,
  259.                                     87,
  260.                                     88,
  261.                                     90,
  262.                                     91,
  263.                                     92,
  264.                                     93,
  265.                                     94,
  266.                                     95,
  267.                                     96,
  268.                                     98,
  269.                                     99,
  270.                                     100,
  271.                                     102,
  272.                                     104,
  273.                                     105,
  274.                                     106,
  275.                                     108,
  276.                                     110,
  277.                                     111,
  278.                                     112,
  279.                                     114,
  280.                                     115,
  281.                                     116,
  282.                                     117,
  283.                                     118,
  284.                                     119,
  285.                                     120,
  286.                                     121,
  287.                                     122,
  288.                                     123,
  289.                                     124,
  290.                                     125,
  291.                                     126,
  292.                                     128,
  293.                                     129,
  294.                                     130,
  295.                                     132,
  296.                                     133,
  297.                                     134,
  298.                                     135,
  299.                                     136,
  300.                                     138,
  301.                                     140};
  302.  
  303.     @Before
  304.     public void setUp() {
  305.     }
  306.  
  307.     @After
  308.     public void tearDown() {
  309.     }
  310.  
  311.     @Test
  312.     public void testIsPrime() {
  313.         for (int i : primes)
  314.             assertEquals("Prime test: " + i, true, MathHelpers.isPrimeNumber(i));
  315.         MathHelpers.primes.clear();
  316.         for (int i : nonPrimes)
  317.             assertEquals("Non prime test: " + i, false, MathHelpers.isPrimeNumber(i));
  318.     }
  319. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement