/*
 * @author Ranides Atterwim <ranides@gmail.com>
 * @copyright Ranides Atterwim
 * @license WTFPL
 * @url http://ranides.net/projects/assira
 */

package net.ranides.assira.math;

import org.junit.Test;
import static org.junit.Assert.*;

/**
 *
 * @author Mariusz Sieron <m.sieron@samsung.com>
 */
public class MathUtilsTest {

    @Test
    public void testGCD() {
        assertEquals(1, MathUtils.gcd(7,3));
        assertEquals(2, MathUtils.gcd(2*3*7, 2*2));
        assertEquals(6, MathUtils.gcd(2*3*7, 2*3*5));
        
        assertEquals(6, MathUtils.gcd(2*3*7, 2*3*5, 2*3*11));
        assertEquals(2, MathUtils.gcd(2*3*7, 2*3*5, 2*11));
    }
    
    @Test
    public void testLCM() {
        assertEquals(21, MathUtils.lcm(7,3));
        assertEquals(84, MathUtils.lcm(2*3*7, 2*2));
        assertEquals(210, MathUtils.lcm(2*3*7, 2*3*5));
        
        assertEquals(2310, MathUtils.lcm(2*3*7, 2*3*5, 2*3*11));
        assertEquals(2310, MathUtils.lcm(2*3*7, 2*3*5, 2*11));
    }

    @Test
    public void testLog2floor() {

        assertEquals(2, MathUtils.log2floor(4));
        assertEquals(2, MathUtils.log2floor(5));
        assertEquals(2, MathUtils.log2floor(7));

        assertEquals(3, MathUtils.log2floor(8));
        assertEquals(3, MathUtils.log2floor(9));
        assertEquals(3, MathUtils.log2floor(10));

        assertEquals(16, MathUtils.log2floor(256 * 256));
        assertEquals(24, MathUtils.log2floor(256 * 256 * 256));
        assertEquals(31, MathUtils.log2floor(128 * 256 * 256 * 256));

        assertEquals(30, MathUtils.log2floor(128 * 256 * 256 * 256 - 1000));
        assertEquals(31, MathUtils.log2floor(128 * 256 * 256 * 256 + 1000));

    }

    @Test
    public void testLog2ceil() {

        assertEquals(2, MathUtils.log2ceil(4));
        assertEquals(3, MathUtils.log2ceil(5));
        assertEquals(3, MathUtils.log2ceil(7));

        assertEquals(3, MathUtils.log2ceil(8));
        assertEquals(4, MathUtils.log2ceil(9));
        assertEquals(4, MathUtils.log2ceil(10));

        assertEquals(16, MathUtils.log2ceil(256 * 256));
        assertEquals(24, MathUtils.log2ceil(256 * 256 * 256));
        assertEquals(31, MathUtils.log2ceil(128 * 256 * 256 * 256));

        assertEquals(31, MathUtils.log2ceil(128 * 256 * 256 * 256 - 1000));
        assertEquals(32, MathUtils.log2ceil(128 * 256 * 256 * 256 + 1000));

    }

}
