/**
 * Copyright (c) 2018, RTE (http://www.rte-france.com)
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
package com.powsybl.computation;

import org.junit.Test;

import static org.junit.Assert.assertEquals;

/**
 * @author Yichen Tang <yichen.tang at rte-france.com>
 */
public class PartitionTest {

    @Test
    public void test() {
        Partition p1of1 = Partition.parse("1/1");
        assertEquals(0, p1of1.startIndex(1));
        assertEquals(1, p1of1.endIndex(1));
        assertEquals(0, p1of1.startIndex(2));
        assertEquals(2, p1of1.endIndex(2));

        Partition p1of2 = Partition.parse("1/2");
        Partition p2of2 = Partition.parse("2/2");
        // total:2
        // [0,1) [1,2)
        assertEquals(0, p1of2.startIndex(2));
        assertEquals(1, p1of2.endIndex(2));
        assertEquals(1, p2of2.startIndex(2));
        assertEquals(2, p2of2.endIndex(2));

        Partition p1of3 = Partition.parse("1/3");
        Partition p2of3 = Partition.parse("2/3");
        Partition p3of3 = Partition.parse("3/3");
        // total:5
        // [0,1) [1,3) [3,5)
        assertEquals(0, p1of3.startIndex(5));
        assertEquals(1, p1of3.endIndex(5)); // 1 * 5 / 3
        assertEquals(1, p2of3.startIndex(5)); // (2-1) * 5 / 3
        assertEquals(3, p2of3.endIndex(5)); // 2 * 5 / 3
        assertEquals(3, p3of3.startIndex(5)); // (3-1) * 5 / 3
        assertEquals(5, p3of3.endIndex(5)); // 3 * 5 / 3
    }
}

@@ -319,51 +319,141 @@
 st;%0A
-%0Aimport static org.junit.Assert.assertEqual
+import com.powsybl.commons.PowsyblException;%0A%0Aimport static org.junit.Assert.assertEquals;%0Aimport static org.junit.Assert.assertThrow
 s;%0A%0A
@@ -1610,32 +1610,32 @@
 / (3-1) * 5 / 3%0A
-
         assertEq
@@ -1680,11 +1680,1471 @@
  3%0A    %7D
+%0A%0A    private void assertPartitionInvalid(String s) %7B%0A        PowsyblException exception = assertThrows(PowsyblException.class,%0A            () -%3E Partition.parse(s));%0A        assertEquals(s + %22 is not valid%22, exception.getMessage());%0A    %7D%0A%0A    @Test%0A    public void testInvalid() %7B%0A        //parsing%0A        assertPartitionInvalid(%22a%22);%0A        assertPartitionInvalid(%22/%22);%0A        assertPartitionInvalid(%221%22);%0A        assertPartitionInvalid(%2212%22);%0A        assertPartitionInvalid(%22/1%22);%0A        assertPartitionInvalid(%221/%22);%0A        assertPartitionInvalid(%221%7C2%22);%0A%0A        //invalid values (but parses ok, bug or feature?)%0A        assertPartitionInvalid(%222/1%22);%0A        assertPartitionInvalid(%220/2%22);%0A        assertPartitionInvalid(%22-1/2%22);%0A%0A        // Are the following bugs or features ?%0A        assertThrows(NumberFormatException.class, () -%3E Partition.parse(%22foo/1/2%22));%0A        assertThrows(NumberFormatException.class, () -%3E Partition.parse(%22a1/2%22));%0A        assertThrows(NumberFormatException.class, () -%3E Partition.parse(%22 1/2 %22));%0A        Partition.parse(%22+1/2%22);%0A        Partition.parse(%221/2/foo%22);%0A        %7B%0A            Partition p = Partition.parse(%22+1/+2/foo0/0bar%22);%0A            assertEquals(%221/2%22, p.toString());%0A        %7D%0A        %7B%0A            PowsyblException exception = assertThrows(PowsyblException.class,%0A                () -%3E Partition.parse(%22-0/2%22));%0A            assertEquals(%220/2 is not valid%22, exception.getMessage());%0A        %7D%0A    %7D
 %0A%7D%0A

Add more tests for Partition.parse