mirror of
https://bitbucket.org/Mattrixwv/javaclasses.git
synced 2025-12-07 07:23:57 -05:00
Added function to count occurrences of a char in a string
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
//src/test/java/mattrixwv/TestAlgorithms.java
|
||||
//JavaClasses/src/test/java/mattrixwv/TestAlgorithms.java
|
||||
//Matthew Ellison
|
||||
// Created: 06-07-20
|
||||
//Modified: 06-07-20
|
||||
//Modified: 07-28-20
|
||||
//This class holds many algorithms that I have found it useful to keep around
|
||||
//As such all of the functions in here are static and meant to be used as stand alone functions
|
||||
/*
|
||||
Copyright (C) 2019 Matthew Ellison
|
||||
Copyright (C) 2020 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
|
||||
@@ -347,4 +347,23 @@ public class TestAlgorithms{
|
||||
ArrayList<String> answer = Algorithms.getPermutations(permString);
|
||||
assertEquals("getPermutations failed", correctAnswer, answer);
|
||||
}
|
||||
@Test
|
||||
public void testFindNumOccurrence(){
|
||||
//Test 1
|
||||
String testString = "abcdefgdd";
|
||||
char testChar = 'a';
|
||||
long correctAnswer = 1;
|
||||
long answer = Algorithms.findNumOccurrence(testString, testChar);
|
||||
assertEquals(correctAnswer, answer);
|
||||
//Test 2
|
||||
testChar = 'd';
|
||||
correctAnswer = 3;
|
||||
answer = Algorithms.findNumOccurrence(testString, testChar);
|
||||
assertEquals(correctAnswer, answer);
|
||||
//Test 3
|
||||
testChar = 'h';
|
||||
correctAnswer = 0;
|
||||
answer = Algorithms.findNumOccurrence(testString, testChar);
|
||||
assertEquals(correctAnswer, answer);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user