Skip to content

Commit

Permalink
Some tests for the Nums util.
Browse files Browse the repository at this point in the history
  • Loading branch information
nmihajlovski committed Feb 15, 2018
1 parent 1882752 commit 698a0d9
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 22 deletions.
22 changes: 0 additions & 22 deletions rapidoid-commons/src/test/java/org/rapidoid/util/MscTest.java
Expand Up @@ -23,7 +23,6 @@
import org.junit.Test; import org.junit.Test;
import org.rapidoid.annotation.Authors; import org.rapidoid.annotation.Authors;
import org.rapidoid.annotation.Since; import org.rapidoid.annotation.Since;
import org.rapidoid.commons.Nums;
import org.rapidoid.test.TestCommons; import org.rapidoid.test.TestCommons;


import java.io.File; import java.io.File;
Expand Down Expand Up @@ -100,25 +99,4 @@ public void testUuidBytes() {
eq(uuid2, uuid); eq(uuid2, uuid);
} }


@Test
public void testLog2() {
eq(Nums.log2(1), 0);
eq(Nums.log2(2), 1);

eq(Nums.log2(3), 2);
eq(Nums.log2(4), 2);

eq(Nums.log2(5), 3);
eq(Nums.log2(8), 3);

eq(Nums.log2(9), 4);
eq(Nums.log2(16), 4);

eq(Nums.log2(1024), 10);
eq(Nums.log2(65536), 16);
eq(Nums.log2(65536 * 1024), 26);

eq(Nums.log2(Integer.MAX_VALUE), 31);
}

} }
63 changes: 63 additions & 0 deletions rapidoid-commons/src/test/java/org/rapidoid/util/NumsTest.java
@@ -0,0 +1,63 @@
/*-
* #%L
* rapidoid-commons
* %%
* Copyright (C) 2014 - 2018 Nikolche Mihajlovski and contributors
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/

package org.rapidoid.util;

import org.junit.Test;
import org.rapidoid.annotation.Authors;
import org.rapidoid.annotation.Since;
import org.rapidoid.commons.Nums;
import org.rapidoid.test.TestCommons;

@Authors("Nikolche Mihajlovski")
@Since("5.6.0")
public class NumsTest extends TestCommons {

@Test
public void log2() {
eq(Nums.log2(1), 0);
eq(Nums.log2(2), 1);

eq(Nums.log2(3), 2);
eq(Nums.log2(4), 2);

eq(Nums.log2(5), 3);
eq(Nums.log2(8), 3);

eq(Nums.log2(9), 4);
eq(Nums.log2(16), 4);

eq(Nums.log2(1024), 10);
eq(Nums.log2(65536), 16);
eq(Nums.log2(65536 * 1024), 26);

eq(Nums.log2(Integer.MAX_VALUE), 31);
}

@Test
public void percent() {
eq(Nums.percent(0), 0.0);
eq(Nums.percent(0.9), 90.0);

eq(Nums.percent(0.12341), 12.34);
eq(Nums.percent(0.12349), 12.35);
}

}

0 comments on commit 698a0d9

Please sign in to comment.