Home | History | Annotate | Download | only in spec
      1 /*
      2  *  Licensed to the Apache Software Foundation (ASF) under one or more
      3  *  contributor license agreements.  See the NOTICE file distributed with
      4  *  this work for additional information regarding copyright ownership.
      5  *  The ASF licenses this file to You under the Apache License, Version 2.0
      6  *  (the "License"); you may not use this file except in compliance with
      7  *  the License.  You may obtain a copy of the License at
      8  *
      9  *     http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  *  Unless required by applicable law or agreed to in writing, software
     12  *  distributed under the License is distributed on an "AS IS" BASIS,
     13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  *  See the License for the specific language governing permissions and
     15  *  limitations under the License.
     16  */
     17 
     18 /**
     19 * @author Vladimir N. Molotkov
     20 * @version $Revision$
     21 */
     22 
     23 package tests.security.spec;
     24 
     25 import dalvik.annotation.TestTargets;
     26 import dalvik.annotation.TestLevel;
     27 import dalvik.annotation.TestTargetNew;
     28 import dalvik.annotation.TestTargetClass;
     29 
     30 import junit.framework.TestCase;
     31 
     32 import java.math.BigInteger;
     33 import java.security.spec.ECFieldF2m;
     34 import java.util.Arrays;
     35 import java.util.Random;
     36 
     37 /**
     38  * Tests for <code>ECFieldF2m</code> class fields and methods.
     39  *
     40  */
     41 @TestTargetClass(ECFieldF2m.class)
     42 public class ECFieldF2mTest extends TestCase {
     43 
     44     /**
     45      * Support class for this test.
     46      * Encapsulates <code>ECFieldF2m</code> testing
     47      * domain parameters.
     48      *
     49      */
     50     private static final class ECFieldF2mDomainParams {
     51 
     52         /**
     53          * <code>NPE</code> reference object of class NullPointerException.
     54          * NullPointerException must be thrown by <code>ECFieldF2m</code>
     55          * ctors in some circumstances
     56          */
     57         static final NullPointerException NPE = new NullPointerException();
     58         /**
     59          * <code>IArgE</code> reference object of class IllegalArgumentException.
     60          * IllegalArgumentException must be thrown by <code>ECFieldF2m</code>
     61          * ctors in some circumstances
     62          */
     63         static final IllegalArgumentException IArgE = new IllegalArgumentException();
     64 
     65         /**
     66          * The <code>m</code> parameter for <code>ECFieldF2m</code>
     67          * ctor for the current test.
     68          */
     69         final int m;
     70         /**
     71          * The <code>rp</code> parameter for <code>ECFieldF2m</code>
     72          * ctor for the current test.
     73          */
     74         final BigInteger rp;
     75         /**
     76          * The <code>ks</code> parameter for <code>ECFieldF2m</code>
     77          * ctor for the current test.
     78          */
     79         final int[] ks;
     80 
     81 
     82         /**
     83          * Exception expected with this parameters set or <code>null</code>
     84          * if no exception expected.
     85          */
     86         final Exception x;
     87 
     88         /**
     89          * Constructs ECFieldF2mDomainParams
     90          *
     91          * @param m
     92          * @param rp
     93          * @param ks
     94          * @param expectedException
     95          */
     96         ECFieldF2mDomainParams(final int m,
     97                 final BigInteger rp,
     98                 final int[] ks,
     99                 final Exception expectedException) {
    100             this.m = m;
    101             this.rp = rp;
    102             this.ks = ks;
    103             this.x = expectedException;
    104         }
    105     }
    106 
    107     //
    108     // Tests
    109     //
    110 
    111     /**
    112      * Set of parameters used for <code>ECFieldF2m(int)</code>
    113      * constructor tests.
    114      */
    115     private final ECFieldF2mDomainParams[] intCtorTestParameters =
    116         new ECFieldF2mDomainParams[] {
    117             // set 0: valid m
    118             new ECFieldF2mDomainParams(1, null, null, null),
    119             // set 1: valid m
    120             new ECFieldF2mDomainParams(Integer.MAX_VALUE, null, null, null),
    121             // set 2: invalid m
    122             new ECFieldF2mDomainParams(0, null, null, ECFieldF2mDomainParams.IArgE),
    123             // set 3: invalid m
    124             new ECFieldF2mDomainParams(-1, null, null, ECFieldF2mDomainParams.IArgE)
    125         };
    126 
    127     /**
    128      * Tests for constructor <code>ECFieldF2m(int)</code><br>
    129      *
    130      * Assertion: constructs new <code>ECFieldF2m</code> object
    131      * using valid parameter m.
    132      *
    133      * Assertion: IllegalArgumentException if m is not positive.
    134      */
    135     @TestTargetNew(
    136         level = TestLevel.COMPLETE,
    137         notes = "",
    138         method = "ECFieldF2m",
    139         args = {int.class}
    140     )
    141     public final void testECFieldF2mint() {
    142         for(int i=0; i<intCtorTestParameters.length; i++) {
    143             ECFieldF2mDomainParams tp = intCtorTestParameters[i];
    144             try {
    145                 // perform test
    146                 new ECFieldF2m(tp.m);
    147 
    148                 if (tp.x != null) {
    149                     // exception has been expected
    150                     fail(getName() + ", set " + i +
    151                             " FAILED: expected exception has not been thrown");
    152                 }
    153             } catch (Exception e){
    154                 if (tp.x == null || !e.getClass().isInstance(tp.x)) {
    155                     // exception: failure
    156                     // if it has not been expected
    157                     // or wrong one has been thrown
    158                     fail(getName() + ", set " + i +
    159                             " FAILED: unexpected " + e);
    160                 }
    161             }
    162         }
    163     }
    164 
    165     /**
    166      * Set of parameters used for <code>ECFieldF2m(int, int[] ks)</code>
    167      * constructor tests.
    168      */
    169     private final ECFieldF2mDomainParams[] constructorTestParameters =
    170         new ECFieldF2mDomainParams[] {
    171             // set 0: valid m and ks - trinomial basis params
    172             new ECFieldF2mDomainParams(
    173                     1999,
    174                     new BigInteger("57406534763712726211641660058884099201115885104434760023882136841288313069618515692832974315825313495922298231949373138672355948043152766571296567808332659269564994572656140000344389574120022435714463495031743122390807731823194181973658513020233176985452498279081199404472314802811655824768082110985166340672084454492229252801189742403957029450467388250214501358353312915261004066118140645880633941658603299497698209063510889929202021079926591625770444716951045960277478891794836019580040978908928741972740865961716524153209532713803393514722581342474556943840519615081302148762454520131486413662191617"),
    175                     new int[] {367},
    176                     null),
    177             // set 1: valid m and ks - pentanomial basis params
    178             new ECFieldF2mDomainParams(
    179                     2000,
    180                     new BigInteger("114813069527425452423283320117768198402231770208869520047764273682576626139237031385665948631650626991844596463898746277344711896086305533142593135616665318539129989145312280000688779148240044871428926990063486244781615463646388363947317026040466353970904996558162398808944629605623311649536164221970332681364606313754094036473740741389411285817465477407288087941692709593079057904974473325399237449961796178150263073811552931156681807161003582337510008648338765664631815874608789366699668224806907571505750798647855797220056285479869767291137153732790597348308446887230584637235716444920907512810569735"),
    181                     new int[] {981,2,1},
    182                     null),
    183             // set 2: valid m, invalid (null) pr, invalid (null) ks
    184             new ECFieldF2mDomainParams(
    185                     1963,
    186                     null,
    187                     null,
    188                     ECFieldF2mDomainParams.NPE),
    189             // set 3: valid m, invalid pr, invalid ks - wrong length
    190             new ECFieldF2mDomainParams(
    191                     1963,
    192                     new BigInteger("114813069527425452423283320117768198402231770208869520047764273682576626139237031385665948631650626991844596463898746277344711896086305533142593135616665318539129989145312280000688779148240044871428926990063486244781615463646388363947317026040466353970904996558162398808944629605623311649536164221970332681364606313754094036473740741389411285817465477407288087941692709593079057904974473325399237449961796178150263073811552931156681807161003582337510008648338765664631815874608789366699668224806907571505750798647855797220056285479869767291137153732790597348308446887230584637235716444920907512810569734"),
    193                     new int[] {981,2},
    194                     ECFieldF2mDomainParams.IArgE),
    195             // set 4: valid m, invalid ks - wrong length
    196             new ECFieldF2mDomainParams(
    197                     1963,
    198                     new BigInteger("5"),
    199                     new int[] {981,124,2,1},
    200                     ECFieldF2mDomainParams.IArgE),
    201             // set 5: valid m, invalid ks - wrong value
    202             new ECFieldF2mDomainParams(
    203                     1999,
    204                     new BigInteger("5"),
    205                     new int[] {1999},
    206                     ECFieldF2mDomainParams.IArgE),
    207             // set 6: valid m, invalid ks - wrong value
    208             new ECFieldF2mDomainParams(
    209                     1999,
    210                     new BigInteger("5"),
    211                     new int[] {0},
    212                     ECFieldF2mDomainParams.IArgE),
    213             // set 7: valid m, invalid ks - wrong values
    214             new ECFieldF2mDomainParams(
    215                     2000,
    216                     new BigInteger("5"),
    217                     new int[] {2000,2,1},
    218                     ECFieldF2mDomainParams.IArgE),
    219             // set 8: valid m, invalid ks - wrong values
    220             new ECFieldF2mDomainParams(
    221                     2000,
    222                     new BigInteger("5"),
    223                     new int[] {981,2,0},
    224                     ECFieldF2mDomainParams.IArgE),
    225             // set 9: invalid m
    226             new ECFieldF2mDomainParams(
    227                     -5,
    228                     new BigInteger("114813069527425452423283320117768198402231770208869520047764273682576626139237031385665948631650626991844596463898746277344711896086305533142593135616665318539129989145312280000688779148240044871428926990063486244781615463646388363947317026040466353970904996558162398808944629605623311649536164221970332681364606313754094036473740741389411285817465477407288087941692709593079057904974473325399237449961796178150263073811552931156681807161003582337510008648338765664631815874608789366699668224806907571505750798647855797220056285479869767291137153732790597348308446887230584637235716444920907512810569735"),
    229                     new int[] {981,2,1},
    230                     ECFieldF2mDomainParams.IArgE),
    231             // set 10: valid m, invalid ks - wrong order
    232             new ECFieldF2mDomainParams(
    233                     2000,
    234                     new BigInteger("5"),
    235                     new int[] {981,1,2},
    236                     ECFieldF2mDomainParams.IArgE),
    237             // set 11: valid m, invalid ks - no content
    238             new ECFieldF2mDomainParams(
    239                     2000,
    240                     new BigInteger("5"),
    241                     new int[3],
    242                     ECFieldF2mDomainParams.IArgE),
    243             // set 12: valid m, invalid ks - length is 0
    244             new ECFieldF2mDomainParams(
    245                     2000,
    246                     new BigInteger("0"),
    247                     new int[0],
    248                     ECFieldF2mDomainParams.IArgE),
    249         };
    250 
    251     /**
    252      * Tests for constructor <code>ECFieldF2m(int m, int[] ks)</code><br>
    253      *
    254      * Assertion: constructs new <code>ECFieldF2m</code> object
    255      * using valid parameters m and rp. ks represents trinomial basis.
    256      *
    257      * Assertion: constructs new <code>ECFieldF2m</code> object
    258      * using valid parameters m and ks. ks represents pentanomial basis.
    259      *
    260      * Assertion: IllegalArgumentException if m is not positive.
    261      *
    262      * Assertion: NullPointerException if ks is null.
    263      *
    264      * Assertion: IllegalArgumentException if ks is invalid.
    265      */
    266     @TestTargetNew(
    267         level = TestLevel.COMPLETE,
    268         notes = "",
    269         method = "ECFieldF2m",
    270         args = {int.class, int[].class}
    271     )
    272     public final void testECFieldF2mintintArray() {
    273         for(int i=0; i<constructorTestParameters.length; i++) {
    274             ECFieldF2mDomainParams tp = constructorTestParameters[i];
    275             try {
    276                 // perform test
    277                 ECFieldF2m test = new ECFieldF2m(tp.m, tp.ks);
    278 
    279                 if (tp.x != null) {
    280                     // exception has been expected
    281                     fail(getName() + ", set " + i +
    282                             " FAILED: expected exception has not been thrown");
    283                 }
    284             } catch (Exception e){
    285                 if (tp.x == null || !e.getClass().isInstance(tp.x)) {
    286                     // exception: failure
    287                     // if it has not been expected
    288                     // or wrong one has been thrown
    289                     fail(getName() + ", set " + i +
    290                             " FAILED: unexpected " + e);
    291                 }
    292             }
    293         }
    294     }
    295 
    296     /**
    297      * Tests for constructor <code>ECFieldF2m(int m, BigInteger rp)</code><br>
    298      *
    299      * Assertion: constructs new <code>ECFieldF2m</code> object
    300      * using valid parameters m and rp.
    301      *
    302      * Assertion: constructs new <code>ECFieldF2m</code> object
    303      * using valid parameters m and rp.
    304      *
    305      * Assertion: IllegalArgumentException if m is not positive.
    306      *
    307      * Assertion: NullPointerException if rp is null.
    308      *
    309      * Assertion: IllegalArgumentException if rp is invalid.
    310      */
    311     @TestTargetNew(
    312         level = TestLevel.COMPLETE,
    313         method = "ECFieldF2m",
    314         args = {int.class, java.math.BigInteger.class}
    315     )
    316     public final void testECFieldF2mintBigInteger() {
    317         for(int i=0; i<constructorTestParameters.length; i++) {
    318             ECFieldF2mDomainParams tp = constructorTestParameters[i];
    319             try {
    320                 // perform test
    321                 new ECFieldF2m(tp.m, tp.rp);
    322 
    323                 if (tp.x != null) {
    324                     // exception has been expected
    325                     fail(getName() + ", set " + i +
    326                             " FAILED: expected exception has not been thrown");
    327                 }
    328             } catch (Exception e){
    329                 if (tp.x == null || !e.getClass().isInstance(tp.x)) {
    330                     // exception: failure
    331                     // if it has not been expected
    332                     // or wrong one has been thrown
    333                     fail(getName() + ", set " + i +
    334                             " FAILED: unexpected " + e);
    335                 }
    336             }
    337         }
    338     }
    339 
    340     /**
    341      * Test #1 for <code>hashCode()</code> method.<br>
    342      *
    343      * Assertion: must return the same value if invoked
    344      * repeatedly on the same object.
    345      */
    346     @TestTargetNew(
    347         level = TestLevel.PARTIAL_COMPLETE,
    348         notes = "",
    349         method = "hashCode",
    350         args = {}
    351     )
    352     public final void testHashCode01() {
    353         ECFieldF2m f = new ECFieldF2m(2000);
    354         int hc = f.hashCode();
    355         assertTrue(hc == f.hashCode() &&
    356                    hc == f.hashCode() &&
    357                    hc == f.hashCode() &&
    358                    hc == f.hashCode() &&
    359                    hc == f.hashCode() &&
    360                    hc == f.hashCode() &&
    361                    hc == f.hashCode() &&
    362                    hc == f.hashCode());
    363     }
    364 
    365     /**
    366      * Test #2 for <code>hashCode()</code> method.<br>
    367      *
    368      * Assertion: must return the same value if invoked
    369      * repeatedly on the same object.
    370      */
    371     @TestTargetNew(
    372         level = TestLevel.PARTIAL_COMPLETE,
    373         notes = "",
    374         method = "hashCode",
    375         args = {}
    376     )
    377     public final void testHashCode02() {
    378         ECFieldF2m f = new ECFieldF2m(2000, new int[] {981, 2, 1});
    379         int hc = f.hashCode();
    380         assertTrue(hc == f.hashCode() &&
    381                    hc == f.hashCode() &&
    382                    hc == f.hashCode() &&
    383                    hc == f.hashCode() &&
    384                    hc == f.hashCode() &&
    385                    hc == f.hashCode() &&
    386                    hc == f.hashCode() &&
    387                    hc == f.hashCode());
    388     }
    389 
    390     /**
    391      * Test #3 for <code>hashCode()</code> method.<br>
    392      *
    393      * Assertion: must return the same value if invoked
    394      * on equal (according to the <code>equals(Object)</code> method) objects.
    395      */
    396     @TestTargetNew(
    397         level = TestLevel.PARTIAL_COMPLETE,
    398         notes = "",
    399         method = "hashCode",
    400         args = {}
    401     )
    402     public final void testHashCode03() {
    403         assertTrue(new ECFieldF2m(111).hashCode() ==
    404                    new ECFieldF2m(111).hashCode());
    405     }
    406 
    407     /**
    408      * Test #4 for <code>hashCode()</code> method.<br>
    409      *
    410      * Assertion: must return the same value if invoked
    411      * on equal (according to the <code>equals(Object)</code> method) objects.
    412      */
    413     @TestTargetNew(
    414         level = TestLevel.PARTIAL_COMPLETE,
    415         notes = "",
    416         method = "hashCode",
    417         args = {}
    418     )
    419     public final void testHashCode04() {
    420         assertTrue(new ECFieldF2m(2000, new int[] {981, 2, 1}).hashCode() ==
    421                    new ECFieldF2m(2000, new int[] {981, 2, 1}).hashCode());
    422     }
    423 
    424     /**
    425      * Test #5 for <code>hashCode()</code> method.<br>
    426      *
    427      * Assertion: must return the same value if invoked
    428      * on equal (according to the <code>equals(Object)</code> method) objects.
    429      */
    430     @TestTargetNew(
    431         level = TestLevel.PARTIAL_COMPLETE,
    432         notes = "",
    433         method = "hashCode",
    434         args = {}
    435     )
    436     public final void testHashCode05() {
    437         assertTrue(new ECFieldF2m(2000, new int[] {981, 2, 1}).hashCode() ==
    438                    new ECFieldF2m(2000, BigInteger.valueOf(0L).
    439                                         setBit(0).setBit(1).setBit(2).
    440                                         setBit(981).setBit(2000)).hashCode());
    441     }
    442 
    443     /**
    444      * Test #1 for <code>equals()</code> method.<br>
    445      *
    446      * Assertion: object equals to itself.
    447      */
    448     @TestTargetNew(
    449         level = TestLevel.PARTIAL_COMPLETE,
    450         notes = "",
    451         method = "equals",
    452         args = {java.lang.Object.class}
    453     )
    454     public final void testEqualsObject01() {
    455         ECFieldF2m obj = new ECFieldF2m(1999, new int[] {367});
    456         assertTrue(obj.equals(obj));
    457     }
    458 
    459     /**
    460      * Test #2 for <code>equals()</code> method.<br>
    461      *
    462      * Assertion: normal basis - objects equal if their m are equal.
    463      */
    464     @TestTargetNew(
    465         level = TestLevel.PARTIAL_COMPLETE,
    466         notes = "Simple test. Doesn't verify other cases.",
    467         method = "equals",
    468         args = {java.lang.Object.class}
    469     )
    470     public final void testEqualsObject02() {
    471         assertTrue(new ECFieldF2m(43).equals(new ECFieldF2m(43)));
    472     }
    473 
    474     /**
    475      * Test #3 for <code>equals()</code> method.<br>
    476      *
    477      * Assertion: trinomial basis - objects equal if their m, and rp
    478      * are mutually equal.
    479      */
    480     @TestTargetNew(
    481         level = TestLevel.PARTIAL_COMPLETE,
    482         notes = "",
    483         method = "equals",
    484         args = {java.lang.Object.class}
    485     )
    486     public final void testEqualsObject03() {
    487         assertTrue(new ECFieldF2m(1999, new int[] {367}).equals(
    488                    new ECFieldF2m(1999, BigInteger.valueOf(0L).
    489                                         setBit(0).setBit(367).setBit(1999))));
    490     }
    491 
    492     /**
    493      * Test #4 for <code>equals()</code> method.<br>
    494      *
    495      * Assertion: pentanomial basis - objects equal if their m, and rp
    496      * are mutually equal.
    497      */
    498     @TestTargetNew(
    499         level = TestLevel.PARTIAL_COMPLETE,
    500         notes = "",
    501         method = "equals",
    502         args = {java.lang.Object.class}
    503     )
    504     public final void testEqualsObject04() {
    505         ECFieldF2m f1 = new ECFieldF2m(2000, new int[] {981, 2, 1});
    506         ECFieldF2m f2 = new ECFieldF2m(2000, BigInteger.valueOf(0L).
    507                 setBit(0).setBit(1).setBit(2).
    508                 setBit(981).setBit(2000));
    509         assertTrue(f1.equals(f2) && f2.equals(f1));
    510     }
    511 
    512     /**
    513      * Test #5 for <code>equals()</code> method.<br>
    514      *
    515      * Assertion: objects equal if their m, and rp are mutually equal.
    516      */
    517     @TestTargetNew(
    518         level = TestLevel.PARTIAL_COMPLETE,
    519         notes = "",
    520         method = "equals",
    521         args = {java.lang.Object.class}
    522     )
    523     public final void testEqualsObject05() {
    524         ECFieldF2m f1 = new ECFieldF2m(2000);
    525         ECFieldF2m f2 = new ECFieldF2m(2000, BigInteger.valueOf(0L).
    526                 setBit(0).setBit(1).setBit(2).
    527                 setBit(981).setBit(2000));
    528         assertFalse(f1.equals(f2) || f2.equals(f1));
    529     }
    530 
    531     /**
    532      * Test #6 for <code>equals(Object obj)</code> method.<br>
    533      *
    534      * Assertion: returns false if obj is <code>null</code>
    535      */
    536     @TestTargetNew(
    537         level = TestLevel.PARTIAL_COMPLETE,
    538         notes = "",
    539         method = "equals",
    540         args = {java.lang.Object.class}
    541     )
    542     public final void testEqualsObject06() {
    543         assertFalse(new ECFieldF2m(2000).equals(null));
    544     }
    545 
    546     /**
    547      * Test #7 for <code>equals(Object obj)</code> method.<br>
    548      *
    549      * Assertion: returns false if obj is not instance of <code>ECFieldF2m</code>
    550      */
    551     @TestTargetNew(
    552         level = TestLevel.PARTIAL_COMPLETE,
    553         notes = "",
    554         method = "equals",
    555         args = {java.lang.Object.class}
    556     )
    557     public final void testEqualsObject07() {
    558         assertFalse(new ECFieldF2m(2000).equals(new Object()));
    559     }
    560 
    561     /**
    562      * Test for <code>getFieldSize()</code> method.<br>
    563      *
    564      * Assertion: returns m value for <code>ECFieldF2m</code>
    565      */
    566     @TestTargetNew(
    567         level = TestLevel.COMPLETE,
    568         notes = "",
    569         method = "getFieldSize",
    570         args = {}
    571     )
    572     public final void testGetFieldSize() {
    573         assertEquals(2000, new ECFieldF2m(2000).getFieldSize());
    574     }
    575 
    576     /**
    577      * Test for <code>getM()</code> method.<br>
    578      *
    579      * Assertion: returns m value for <code>ECFieldF2m</code>
    580      */
    581     @TestTargetNew(
    582         level = TestLevel.COMPLETE,
    583         notes = "",
    584         method = "getM",
    585         args = {}
    586     )
    587     public final void testGetM() {
    588         assertEquals(2000, new ECFieldF2m(2000).getM());
    589     }
    590 
    591     /**
    592      * Test #1 for <code>getMidTermsOfReductionPolynomial()</code> method.<br>
    593      *
    594      * Assertion: returns mid terms of reduction polynomial
    595      */
    596     @TestTargetNew(
    597         level = TestLevel.PARTIAL_COMPLETE,
    598         notes = "Verifies that getMidTermsOfReductionPolynomial method returns mid terms of reduction polynomial.",
    599         method = "getMidTermsOfReductionPolynomial",
    600         args = {}
    601     )
    602     public final void testGetMidTermsOfReductionPolynomial01() {
    603         int[] a = new int[] {981,2,1};
    604         int[] b = new ECFieldF2m(2000,
    605                 BigInteger.valueOf(0L).setBit(0).setBit(1).
    606                 setBit(2).setBit(981).setBit(2000)).
    607                 getMidTermsOfReductionPolynomial();
    608         assertTrue(Arrays.equals(a, b));
    609     }
    610 
    611     /**
    612      * Test #2 for <code>getMidTermsOfReductionPolynomial()</code> method.<br>
    613      *
    614      * Assertion: returns null for normal basis
    615      */
    616     @TestTargetNew(
    617         level = TestLevel.PARTIAL_COMPLETE,
    618         notes = "Verifies that getMidTermsOfReductionPolynomial method returns null for normal basis.",
    619         method = "getMidTermsOfReductionPolynomial",
    620         args = {}
    621     )
    622     public final void testGetMidTermsOfReductionPolynomial02() {
    623         assertNull(new ECFieldF2m(2000).getMidTermsOfReductionPolynomial());
    624     }
    625 
    626     /**
    627      * Test #3 for <code>getMidTermsOfReductionPolynomial()</code> method.<br>
    628      *
    629      * Assertion: returns mid terms of reduction polynomial
    630      */
    631     @TestTargetNew(
    632         level = TestLevel.PARTIAL_COMPLETE,
    633         notes = "Verifies that getMidTermsOfReductionPolynomial method returns mid terms of reduction polynomial.",
    634         method = "getMidTermsOfReductionPolynomial",
    635         args = {}
    636     )
    637     public final void testGetMidTermsOfReductionPolynomial03() {
    638         int[] a = new int[] {367};
    639         int[] b = new ECFieldF2m(1999, a).getMidTermsOfReductionPolynomial();
    640         assertTrue(Arrays.equals(a, b));
    641     }
    642 
    643     /**
    644      * Test #1 for <code>getReductionPolynomial()</code> method.<br>
    645      *
    646      * Assertion: returns reduction polynomial
    647      */
    648     @TestTargetNew(
    649         level = TestLevel.PARTIAL_COMPLETE,
    650         notes = "Verifies that getReductionPolynomial method returns reduction polynomial.",
    651         method = "getReductionPolynomial",
    652         args = {}
    653     )
    654     public final void testGetReductionPolynomial01() {
    655         BigInteger rp = BigInteger.valueOf(0L).setBit(0).setBit(1).setBit(2).
    656         setBit(981).setBit(2000);
    657         assertTrue(new ECFieldF2m(2000, rp).getReductionPolynomial().equals(rp));
    658     }
    659 
    660     /**
    661      * Test #2 for <code>getReductionPolynomial()</code> method.<br>
    662      *
    663      * Assertion: returns null for normal basis
    664      */
    665     @TestTargetNew(
    666         level = TestLevel.PARTIAL_COMPLETE,
    667         notes = "Verifies that getReductionPolynomial method returns null for normal basis.",
    668         method = "getReductionPolynomial",
    669         args = {}
    670     )
    671     public final void testGetReductionPolynomial02() {
    672         assertNull(new ECFieldF2m(2000).getReductionPolynomial());
    673     }
    674 
    675     /**
    676      * Tests that object state is preserved against modifications
    677      * through array reference passed to the constructor.
    678      */
    679     @TestTargetNew(
    680         level = TestLevel.PARTIAL,
    681         notes = "Verifies that object state is preserved against modifications through array reference passed to the constructor.",
    682         method = "ECFieldF2m",
    683         args = {int.class, int[].class}
    684     )
    685     public final void testIsStatePreserved01() {
    686         // reference array
    687         int[] a = new int[] {367};
    688         // reference array copy
    689         int[] aCopy = a.clone();
    690         // create obj using copy
    691         ECFieldF2m f = new ECFieldF2m(1999, aCopy);
    692         // modify copy
    693         aCopy[0] = 5;
    694         // compare reference with returned array
    695         assertTrue(Arrays.equals(a, f.getMidTermsOfReductionPolynomial()));
    696     }
    697 
    698     /**
    699      * Tests that object state is preserved against
    700      * modifications through array reference returned by
    701      * <code>getMidTermsOfReductionPolynomial()</code> method.
    702      */
    703     @TestTargets({
    704         @TestTargetNew(
    705             level = TestLevel.PARTIAL,
    706             notes = "Verifies that object state is preserved against modifications through array reference returned by getMidTermsOfReductionPolynomial() method.",
    707             method = "ECFieldF2m",
    708             args = {int.class, int[].class}
    709         ),
    710         @TestTargetNew(
    711             level = TestLevel.PARTIAL,
    712             notes = "Verifies that object state is preserved against modifications through array reference returned by getMidTermsOfReductionPolynomial() method.",
    713             method = "getMidTermsOfReductionPolynomial",
    714             args = {}
    715         )
    716     })
    717     public final void testIsStatePreserved02() {
    718         // reference array
    719         int[] a = new int[] {981,2,1};
    720         // reference array copy
    721         int[] aCopy = a.clone();
    722         // create obj using copy
    723         ECFieldF2m f = new ECFieldF2m(2000, aCopy);
    724         // get array reference and modify returned array
    725         f.getMidTermsOfReductionPolynomial()[0] = 1532;
    726         // compare reference with returned for the second time array
    727         assertTrue(Arrays.equals(a, f.getMidTermsOfReductionPolynomial()));
    728     }
    729 
    730 }
    731