mirror of
https://bitbucket.org/Mattrixwv/javaclasses.git
synced 2025-12-07 07:23:57 -05:00
Added number generators
This commit is contained in:
@@ -19,7 +19,7 @@
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package mattrixwv;
|
||||
package com.mattrixwv;
|
||||
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
@@ -19,7 +19,7 @@
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package mattrixwv;
|
||||
package com.mattrixwv;
|
||||
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
@@ -33,7 +33,7 @@ import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import mattrixwv.exceptions.InvalidResult;
|
||||
import com.mattrixwv.exceptions.InvalidResult;
|
||||
|
||||
|
||||
public class TestNumberAlgorithms{
|
||||
@@ -22,7 +22,7 @@ Copyright (C) 2022 Matthew Ellison
|
||||
*/
|
||||
|
||||
|
||||
package mattrixwv;
|
||||
package com.mattrixwv;
|
||||
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
@@ -31,7 +31,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import mattrixwv.exceptions.InvalidResult;
|
||||
import com.mattrixwv.exceptions.InvalidResult;
|
||||
|
||||
|
||||
public class TestStopwatch{
|
||||
@@ -19,7 +19,7 @@
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package mattrixwv;
|
||||
package com.mattrixwv;
|
||||
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
45
src/test/java/com/mattrixwv/TestTriple.java
Normal file
45
src/test/java/com/mattrixwv/TestTriple.java
Normal file
@@ -0,0 +1,45 @@
|
||||
//JavaClasses/src/test/java/com/mattrixwv/TestTriple.java
|
||||
//Mattrixwv
|
||||
// Created: 08-20-22
|
||||
//Modified: 08-20-22
|
||||
/*
|
||||
Copyright (C) 2022 Matthew Ellison
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.mattrixwv;
|
||||
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
||||
public class TestTriple{
|
||||
@Test
|
||||
public void testTriple(){
|
||||
Triple<Long, Long, Long> longTriple1 = new Triple<Long, Long, Long>(1L, 2L, 3L);
|
||||
Triple<Long, Long, Long> longTriple2 = new Triple<Long, Long, Long>(1L, 2L, 3L);
|
||||
Triple<Long, Long, Long> longTriple3 = new Triple<Long, Long, Long>(3L, 2L, 1L);
|
||||
assertEquals(1L, longTriple1.getA());
|
||||
assertEquals(2L, longTriple1.getB());
|
||||
assertEquals(3L, longTriple1.getC());
|
||||
assertEquals(true, longTriple1.equals(longTriple1));
|
||||
assertEquals(true, longTriple1.equals(longTriple2));
|
||||
assertEquals(false, longTriple1.equals(longTriple3));
|
||||
assertEquals(false, longTriple1.equals(1L));
|
||||
assertEquals(Long.hashCode(1) + Long.hashCode(2) * Long.hashCode(3), longTriple1.hashCode());
|
||||
assertEquals("[1, 2, 3]", longTriple1.toString());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
//JavaClasses/src/test/java/com/mattrixwv/generators/TestHexagonalNumberGenerator.java
|
||||
//Mattrixwv
|
||||
// Created: 08-20-22
|
||||
//Modified: 08-20-22
|
||||
/*
|
||||
Copyright (C) 2022 Matthew Ellison
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.mattrixwv.generators;
|
||||
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
||||
public class TestHexagonalNumberGenerator{
|
||||
@Test
|
||||
public void hexagonalNumberGeneratorTest(){
|
||||
HexagonalNumberGenerator gen = new HexagonalNumberGenerator();
|
||||
List<Long> nums = Arrays.asList(1L, 6L, 15L, 28L, 45L, 66L, 91L, 120L, 153L);
|
||||
ArrayList<Long> generatedNums = new ArrayList<>();
|
||||
for(int cnt = 0;cnt < nums.size();++cnt){
|
||||
generatedNums.add(gen.next());
|
||||
}
|
||||
assertEquals(nums, generatedNums);
|
||||
assertEquals(true, gen.hasNext());
|
||||
assertEquals(true, HexagonalNumberGenerator.isHexagonal(153L));
|
||||
assertEquals(false, HexagonalNumberGenerator.isHexagonal(154L));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
//JavaClasses/src/test/java/com/mattrixwv/generators/TestPentagonalNumberGenerator.java
|
||||
//Mattrixwv
|
||||
// Created: 08-20-22
|
||||
//Modified: 08-20-22
|
||||
/*
|
||||
Copyright (C) 2022 Matthew Ellison
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.mattrixwv.generators;
|
||||
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
||||
public class TestPentagonalNumberGenerator{
|
||||
@Test
|
||||
public void pentagonalNumberGeneratorTest(){
|
||||
PentagonalNumberGenerator gen = new PentagonalNumberGenerator();
|
||||
List<Long> nums = Arrays.asList(1L, 5L, 12L, 22L, 35L, 51L, 70L, 92L, 117L);
|
||||
ArrayList<Long> generatedNums = new ArrayList<>();
|
||||
for(int cnt = 0;cnt < nums.size();++cnt){
|
||||
generatedNums.add(gen.next());
|
||||
}
|
||||
assertEquals(nums, generatedNums);
|
||||
assertEquals(true, gen.hasNext());
|
||||
assertEquals(true, PentagonalNumberGenerator.isPentagonal(117L));
|
||||
assertEquals(false, PentagonalNumberGenerator.isPentagonal(118L));
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@ Copyright (C) 2022 Matthew Ellison
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package mattrixwv;
|
||||
package com.mattrixwv.generators;
|
||||
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
@@ -0,0 +1,47 @@
|
||||
//JavaClasses/src/test/java/com/mattrixwv/generators/TestTriangularNumberGenerator.java
|
||||
//Mattrixwv
|
||||
// Created: 08-20-22
|
||||
//Modified: 08-20-22
|
||||
/*
|
||||
Copyright (C) 2022 Matthew Ellison
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.mattrixwv.generators;
|
||||
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
||||
public class TestTriangularNumberGenerator{
|
||||
@Test
|
||||
public void triangularNumberGeneratorTest(){
|
||||
TriangularNumberGenerator gen = new TriangularNumberGenerator();
|
||||
List<Long> nums = Arrays.asList(1L, 3L, 6L, 10L, 15L, 21L, 28L, 36L, 45L);
|
||||
ArrayList<Long> generatedNums = new ArrayList<>();
|
||||
for(int cnt = 0;cnt < nums.size();++cnt){
|
||||
generatedNums.add(gen.next());
|
||||
}
|
||||
assertEquals(nums, generatedNums);
|
||||
assertEquals(true, gen.hasNext());
|
||||
assertEquals(true, TriangularNumberGenerator.isTriangular(55L));
|
||||
assertEquals(false, TriangularNumberGenerator.isTriangular(54L));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user