This repository has been archived by the owner on Jul 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fefbbd8
commit 0234b13
Showing
8 changed files
with
223 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
app/src/main/java/com/example/week9fm5cc5/helpers/GenerateAscii.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.example.week9fm5cc5.helpers; | ||
|
||
import java.util.*; | ||
import java.lang.*; | ||
|
||
public class GenerateAscii { | ||
|
||
/* | ||
|------------------------------- | ||
| Sum | ||
|------------------------------- | ||
*/ | ||
public int sum(String string) { | ||
int sum = 0; | ||
|
||
for (int i=0; i < string.length(); i++) { | ||
int asciiValue = string.charAt(i); | ||
sum += asciiValue; | ||
} | ||
|
||
return sum; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
app/src/main/java/com/example/week9fm5cc5/helpers/ReplaceCharacters.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.example.week9fm5cc5.helpers; | ||
|
||
import java.util.*; | ||
import java.lang.*; | ||
|
||
public class ReplaceCharacters { | ||
|
||
/* | ||
|------------------------------- | ||
| Generate | ||
| FM5CC5 | ||
| f => m , F => M | ||
| 5 => c, 5 => C, (no logic) | ||
| c => c, C => C, (no logic) | ||
| c => 5, C => 5 | ||
|------------------------------- | ||
*/ | ||
public String generate(String string) { | ||
|
||
String updatedString = string | ||
.replace("f", "m") | ||
.replace("F", "M") | ||
.replace("c", "5") | ||
.replace("C", "5"); | ||
|
||
return updatedString; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
app/src/test/java/com/example/week9fm5cc5/helpers/GenerateAsciiTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package com.example.week9fm5cc5.helpers; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
public class GenerateAsciiTest { | ||
GenerateAscii generateAscii; | ||
|
||
@Before | ||
public void setup() { | ||
generateAscii = new GenerateAscii(); | ||
} | ||
|
||
@Test | ||
public void testEmptyAndSpace() { | ||
assertEquals(0, generateAscii.sum("")); | ||
assertEquals(32, generateAscii.sum(" ")); | ||
assertEquals(64, generateAscii.sum(" ")); | ||
} | ||
|
||
@Test | ||
public void testRandomAlphabet() { | ||
assertEquals(104, generateAscii.sum("h")); | ||
assertEquals(101, generateAscii.sum("e")); | ||
assertEquals(108, generateAscii.sum("l")); | ||
assertEquals(119, generateAscii.sum("w")); | ||
assertEquals(111, generateAscii.sum("o")); | ||
assertEquals(114, generateAscii.sum("r")); | ||
assertEquals(100, generateAscii.sum("d")); | ||
} | ||
|
||
@Test | ||
public void testString() { | ||
assertEquals(104+101+108+119+111+114+100, generateAscii.sum("helword")); | ||
} | ||
|
||
@Test | ||
public void testCustomAlphabet() { | ||
// Azerbaijani (🇦🇿) | ||
assertEquals(231, generateAscii.sum("ç")); | ||
assertEquals(246, generateAscii.sum("ö")); | ||
assertEquals(601, generateAscii.sum("ə")); | ||
assertEquals(287, generateAscii.sum("ğ")); | ||
assertEquals(351, generateAscii.sum("ş")); | ||
assertEquals(305, generateAscii.sum("ı")); | ||
assertEquals(252, generateAscii.sum("ü")); | ||
} | ||
|
||
@Test | ||
public void testNumbers() { | ||
assertEquals(49, generateAscii.sum("1")); | ||
assertEquals(50, generateAscii.sum("2")); | ||
assertEquals(51, generateAscii.sum("3")); | ||
assertEquals(52, generateAscii.sum("4")); | ||
assertEquals(53, generateAscii.sum("5")); | ||
assertEquals(54, generateAscii.sum("6")); | ||
assertEquals(55, generateAscii.sum("7")); | ||
} | ||
|
||
@Test | ||
public void testNonAlpha() { | ||
assertEquals(45, generateAscii.sum("-")); | ||
assertEquals(46, generateAscii.sum(".")); | ||
assertEquals(41, generateAscii.sum(")")); | ||
assertEquals(40, generateAscii.sum("(")); | ||
assertEquals(61, generateAscii.sum("=")); | ||
assertEquals(43, generateAscii.sum("+")); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
app/src/test/java/com/example/week9fm5cc5/helpers/ReplaceCharactersTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.example.week9fm5cc5.helpers; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
public class ReplaceCharactersTest { | ||
ReplaceCharacters replaceCharacters; | ||
|
||
@Before | ||
public void setup() { | ||
replaceCharacters = new ReplaceCharacters(); | ||
} | ||
|
||
@Test | ||
public void testNull() { | ||
assertEquals("", replaceCharacters.generate("")); | ||
assertEquals(" ", replaceCharacters.generate(" ")); | ||
} | ||
|
||
@Test | ||
public void testNoChanges() { | ||
assertEquals("ABDE", replaceCharacters.generate("ABDE")); | ||
assertEquals("abde", replaceCharacters.generate("abde")); | ||
assertEquals("12345", replaceCharacters.generate("12345")); | ||
assertEquals("------", replaceCharacters.generate("------")); | ||
} | ||
|
||
@Test | ||
public void testPositive() { | ||
assertEquals("m", replaceCharacters.generate("f")); | ||
assertEquals("M", replaceCharacters.generate("F")); | ||
assertEquals("5", replaceCharacters.generate("c")); | ||
assertEquals("5", replaceCharacters.generate("C")); | ||
} | ||
|
||
@Test | ||
public void testLongString() { | ||
assertEquals("10m01", replaceCharacters.generate("10f01")); | ||
assertEquals("000000000MAB", replaceCharacters.generate("000000000FAB")); | ||
assertEquals("AAAAAAAAAAAAA5AAAAAAAAAAAA", replaceCharacters.generate("AAAAAAAAAAAAAcAAAAAAAAAAAA")); | ||
assertEquals("ssss--5--ssss", replaceCharacters.generate("ssss--C--ssss")); | ||
} | ||
|
||
@Test | ||
public void testPositiveLong() { | ||
assertEquals("mmmm", replaceCharacters.generate("ffff")); | ||
assertEquals("MMMM", replaceCharacters.generate("FFFF")); | ||
assertEquals("5555", replaceCharacters.generate("cccc")); | ||
assertEquals("5555", replaceCharacters.generate("CCCC")); | ||
} | ||
} |