1 /* 2 * Copyright (c) 2013. John May <jwmay@users.sf.net> 3 * 4 * Contact: cdk-devel@lists.sourceforge.net 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Lesser General Public License 8 * as published by the Free Software Foundation; either version 2.1 9 * of the License, or (at your option) any later version. 10 * All we ask is that proper credit is given for our work, which includes 11 * - but is not limited to - adding the above copyright notice to the beginning 12 * of your source code files, and to any copyright notice that you may distribute 13 * with programs based on this work. 14 * 15 * This program is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License for more details. 19 * 20 * You should have received a copy of the GNU Lesser General Public License 21 * along with this program; if not, write to the Free Software 22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 U 23 */ 24 25 package org.openscience.cdk.hash.stereo; 26 27 import org.junit.Test; 28 29 import static org.junit.Assert.assertEquals; 30 31 /** 32 * @author John May 33 * @cdk.module test-hash 34 */ 35 public class BasicPermutationParityTest { 36 37 BasicPermutationParity permutationParity = new BasicPermutationParity(new int[]{0, 1, 2, 3}); 38 39 @Test(expected = NullPointerException.class) testConstruction_Null()40 public void testConstruction_Null() { 41 new BasicPermutationParity(null); 42 } 43 44 @Test(expected = IllegalArgumentException.class) testConstruction_Empty()45 public void testConstruction_Empty() { 46 new BasicPermutationParity(new int[0]); 47 } 48 49 @Test testParity_Even()50 public void testParity_Even() throws Exception { 51 assertEquals(1, permutationParity.parity(new long[]{4, 3, 2, 1})); 52 } 53 54 @Test testParity_Odd()55 public void testParity_Odd() throws Exception { 56 assertEquals(-1, permutationParity.parity(new long[]{4, 2, 3, 1})); 57 } 58 59 @Test testParity_Even_Negative()60 public void testParity_Even_Negative() throws Exception { 61 assertEquals(1, permutationParity.parity(new long[]{4, 3, -1, -2})); 62 } 63 64 @Test testParity_Odd_Negative()65 public void testParity_Odd_Negative() throws Exception { 66 assertEquals(-1, permutationParity.parity(new long[]{4, -1, 3, -2})); 67 } 68 69 @Test testParity_Duplicate()70 public void testParity_Duplicate() throws Exception { 71 assertEquals(0, permutationParity.parity(new long[]{4, 3, -1, -1})); 72 } 73 74 @Test testParity_All()75 public void testParity_All() throws Exception { 76 assertEquals(1, permutationParity.parity(new long[]{1, 2, 3, 4})); 77 assertEquals(-1, permutationParity.parity(new long[]{2, 1, 3, 4})); 78 assertEquals(-1, permutationParity.parity(new long[]{1, 3, 2, 4})); 79 assertEquals(1, permutationParity.parity(new long[]{3, 1, 2, 4})); 80 assertEquals(1, permutationParity.parity(new long[]{2, 3, 1, 4})); 81 assertEquals(-1, permutationParity.parity(new long[]{3, 2, 1, 4})); 82 assertEquals(-1, permutationParity.parity(new long[]{1, 2, 4, 3})); 83 assertEquals(1, permutationParity.parity(new long[]{2, 1, 4, 3})); 84 assertEquals(1, permutationParity.parity(new long[]{1, 4, 2, 3})); 85 assertEquals(-1, permutationParity.parity(new long[]{4, 1, 2, 3})); 86 assertEquals(-1, permutationParity.parity(new long[]{2, 4, 1, 3})); 87 assertEquals(1, permutationParity.parity(new long[]{4, 2, 1, 3})); 88 assertEquals(1, permutationParity.parity(new long[]{1, 3, 4, 2})); 89 assertEquals(-1, permutationParity.parity(new long[]{3, 1, 4, 2})); 90 assertEquals(-1, permutationParity.parity(new long[]{1, 4, 3, 2})); 91 assertEquals(1, permutationParity.parity(new long[]{4, 1, 3, 2})); 92 assertEquals(1, permutationParity.parity(new long[]{3, 4, 1, 2})); 93 assertEquals(-1, permutationParity.parity(new long[]{4, 3, 1, 2})); 94 assertEquals(-1, permutationParity.parity(new long[]{2, 3, 4, 1})); 95 assertEquals(1, permutationParity.parity(new long[]{3, 2, 4, 1})); 96 assertEquals(1, permutationParity.parity(new long[]{2, 4, 3, 1})); 97 assertEquals(-1, permutationParity.parity(new long[]{4, 2, 3, 1})); 98 assertEquals(-1, permutationParity.parity(new long[]{3, 4, 2, 1})); 99 assertEquals(1, permutationParity.parity(new long[]{4, 3, 2, 1})); 100 101 } 102 103 } 104