//JavaClasses/src/test/java/mattrixwv/TestStringAlgorithms.java //Matthew Ellison // Created: 07-03-21 //Modified: 07-03-21 //This class contains tests for my number algorithms /* Copyright (C) 2021 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 . */ package mattrixwv; import static org.junit.Assert.assertEquals; import java.util.ArrayList; import java.util.Arrays; import org.junit.Test; public class TestStringAlgorithms{ @Test public void testGetPermutations(){ //Test 1 String permString = "012"; ArrayList correctAnswer = new ArrayList(Arrays.asList("012", "021", "102", "120", "201", "210")); ArrayList answer = StringAlgorithms.getPermutations(permString); assertEquals("getPermutations failed", correctAnswer, answer); } @Test public void testFindNumOccurrence(){ //Test 1 String testString = "abcdefgdd"; char testChar = 'a'; long correctAnswer = 1; long answer = StringAlgorithms.findNumOccurrence(testString, testChar); assertEquals("FindNumOccurrence 1 failed", correctAnswer, answer); //Test 2 testChar = 'd'; correctAnswer = 3; answer = StringAlgorithms.findNumOccurrence(testString, testChar); assertEquals("FindNumOccurrence 2 failed", correctAnswer, answer); //Test 3 testChar = 'h'; correctAnswer = 0; answer = StringAlgorithms.findNumOccurrence(testString, testChar); assertEquals("FindNumOccurrence 3 failed", correctAnswer, answer); } @Test public void testIsPalindrome(){ //Test 1 String str = "101"; boolean correctAnswer = true; boolean answer = StringAlgorithms.isPalindrome(str); assertEquals("isPalindrome 1 failed", correctAnswer, answer); //Test 2 str = "100"; correctAnswer = false; answer = StringAlgorithms.isPalindrome(str); assertEquals("isPalindrome 2 failed", correctAnswer, answer); //Test 3 str = ""; correctAnswer = true; answer = StringAlgorithms.isPalindrome(str); assertEquals("isPalindrome 3 failed", correctAnswer, answer); } }