diff --git a/pom.xml b/pom.xml
index 7c1b5e2..16a9dce 100644
--- a/pom.xml
+++ b/pom.xml
@@ -9,7 +9,7 @@
1.0-SNAPSHOT
myClasses
-
+
http://www.example.com
diff --git a/src/main/java/mattrixwv/StringAlgorithms.java b/src/main/java/mattrixwv/StringAlgorithms.java
index 3e4fbc6..4f3db35 100644
--- a/src/main/java/mattrixwv/StringAlgorithms.java
+++ b/src/main/java/mattrixwv/StringAlgorithms.java
@@ -1,7 +1,7 @@
//JavaClasses/src/main/java/mattrixwv/StringAlgorithms.java
//Matthew Ellison
// Created: 07-03-21
-//Modified: 07-03-21
+//Modified: 10-11-21
//This class contains algorithms for strings that I've found it useful to keep around
/*
Copyright (C) 2021 Matthew Ellison
@@ -86,5 +86,29 @@ public class StringAlgorithms{
return false;
}
}
+ //Returns true if the string passed to it is a pandigital
+ public static boolean isPandigital(String str, char bottom, char top){
+ //Return false if top < bottom
+ if(top < bottom){
+ return false;
+ }
+ //Return false if the wrong number of characters are in the string
+ if(str.length() != (top - bottom + 1)){
+ return false;
+ }
+
+ //Make sure that all of the needed characters are in the string exactly one time
+ for(char cnt = bottom;cnt <= top;++cnt){
+ if(findNumOccurrence(str, cnt) != 1){
+ return false;
+ }
+ }
+
+ //If the function has reached this part it has passed all of the falsifying tests
+ return true;
+ }
+ public static boolean isPandigital(String str){
+ return isPandigital(str, '1', '9');
+ }
}
diff --git a/src/test/java/mattrixwv/TestStringAlgorithms.java b/src/test/java/mattrixwv/TestStringAlgorithms.java
index 21ebe1e..77dc0ad 100644
--- a/src/test/java/mattrixwv/TestStringAlgorithms.java
+++ b/src/test/java/mattrixwv/TestStringAlgorithms.java
@@ -1,7 +1,7 @@
//JavaClasses/src/test/java/mattrixwv/TestStringAlgorithms.java
//Matthew Ellison
// Created: 07-03-21
-//Modified: 07-03-21
+//Modified: 10-11-21
//This class contains tests for my number algorithms
/*
Copyright (C) 2021 Matthew Ellison
@@ -76,4 +76,42 @@ public class TestStringAlgorithms{
answer = StringAlgorithms.isPalindrome(str);
assertEquals("isPalindrome 3 failed", correctAnswer, answer);
}
+ @Test
+ public void testIsPandigital(){
+ //Test 1
+ String num = "123456789";
+ boolean correctAnswer = true;
+ boolean answer = StringAlgorithms.isPandigital(num);
+ assertEquals("isPandigital 1 failed", correctAnswer, answer);
+
+ //Test 2
+ num = "123";
+ correctAnswer = true;
+ answer = StringAlgorithms.isPandigital(num, '1', '3');
+ assertEquals("isPandigital 2 failed", correctAnswer, answer);
+
+ //Test 3
+ num = "123";
+ correctAnswer = false;
+ answer = StringAlgorithms.isPandigital(num);
+ assertEquals("isPandigital 3 failed", correctAnswer, answer);
+
+ //Test 4
+ num = "123";
+ correctAnswer = false;
+ answer = StringAlgorithms.isPandigital(num, '3', '1');
+ assertEquals("inPandigital 4 failed", correctAnswer, answer);
+
+ //Test 5
+ num = "1";
+ correctAnswer = true;
+ answer = StringAlgorithms.isPandigital(num, '1', '1');
+ assertEquals("inPandigital 5 failed", correctAnswer, answer);
+
+ //Test 6
+ num = "112";
+ correctAnswer = false;
+ answer = StringAlgorithms.isPandigital(num, '1', '3');
+ assertEquals("inPandigital 6 failed", correctAnswer, answer);
+ }
}