Commit f47ba0c4 authored by tomun's avatar tomun

Merge remote-tracking branch 'origin/master'

parents 6762003e aea810de
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Assessment02-18</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8
public class AssessmentPartTwo {
public int scrabbleScore(String aWord)
{
// 03 -Scrabble Score
// Complete this method so that it returns the scrabble score for the word in aWord
// In scrabble each letter is worth a number of points and each word is worth the
// sum of the scores of the letters in it. For this assignment we will ignore
// double/treble letter/word bonuses.
// The English language points per letter can be found at
// https://en.wikipedia.org/wiki/Scrabble_letter_distributions
// You will need to come up with a way of connecting each letter to its score and
// a way of identifying each letter in the word.
int score = 0;
int [] charScores = {1,3,3,2,1,4,2,4,1,8,5,1,3,1,1,3,10,1,1,1,1,4,4,8,4,10};
for(int i = 0; i < aWord.length(); i++)
{
int pos = Character.toUpperCase(aWord.charAt(i))-65;
score += charScores[pos];
}
return score;
}
public Boolean passwordValidator(String password)
{
// 04 - Password Validator
// Complete this method to validate that the String password
// is a valid password
// A password is valid if it is
// - between 8 and 16 characters long (inclusive)
// - made up of letters (upper or lower), numbers, and the following characters !£$%
// - has at least one lower case letter, one upper case letter and a number
// - does not contain the phrases 'password' or 'passwd'
Boolean valid = false;
Boolean upperLetter = false;
Boolean lowwerLetter = false;
Boolean number = false;
if ( password.toLowerCase().indexOf("passwd") != -1 | password.toLowerCase().indexOf("password") != -1)
{
return false;
}
if(password.length() > 7 && password.length() < 17)
{
for(int i = 0; i < password.length();i++)
{
if(password.charAt(i) <= 90 && password.charAt(i) >= 65)
{
upperLetter = true;
}
if(password.charAt(i) <= 122 && password.charAt(i) >= 97)
{
lowwerLetter = true;
}
if(password.charAt(i) <= 57 && password.charAt(i) >= 48)
{
number = true;
}
if(upperLetter && lowwerLetter && number)
{
return true;
}
}
}
return false;
}
}
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
class AssessmentPartTwoTest {
public static AssessmentPartTwo test;
@BeforeAll
static void setUpBeforeClass() throws Exception {
test = new AssessmentPartTwo();
}
@ParameterizedTest
@DisplayName("Testing scrabbleScore")
@CsvSource({
"rabbit,10",
"speaker,13",
"exactly,19",
"xylophone,24",
"application,17"
})
void testScrabbleScore(String theWord, int expectedScore) {
assertEquals(expectedScore, test.scrabbleScore(theWord));
}
@ParameterizedTest
@DisplayName("Testing passwordValidator")
@CsvSource({
"qw11Ij87,true",
"a834j,false",
"a88drTcdmn45tdgjhj,false",
"pmmfj6793,false",
"PASSWORD,false",
"lo98passwdiI,false",
"oi!Fcv98ij,true"
})
void testPasswordValidator(String thePassword, Boolean expectedResult) {
assertEquals(expectedResult, test.passwordValidator(thePassword));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment