Added number generators

This commit is contained in:
2022-08-20 13:46:58 -04:00
parent e0825fe96e
commit 8f35397177
21 changed files with 441 additions and 17 deletions

View File

@@ -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));
}
}