Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add unit test #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions src/main/java/com/ctci/arraysandstrings/CheckPermutation.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.ctci.arraysandstrings;

import org.junit.Assert;
import org.junit.Test;
import java.util.Arrays;

/**
@@ -54,6 +56,48 @@ private static boolean isOnePermutationOfOtherGivenThatStringsContainOnlyAscii(S
}
return true;
}

@Test
public void isOnePermutationOfOther_tc1_differentlength() {
String s1 = "rama";
String s2 = "mar";
Assert.assertFalse(isOnePermutationOfOther(s1, s2));
}

@Test
public void isOnePermutationOfOther_tc2_isPermutation() {
String s1 = "ram";
String s2 = "mar";
Assert.assertTrue(isOnePermutationOfOther(s1, s2));
}

@Test
public void isOnePermutationOfOther_tc3_notPermutation() {
String s1 = "rama";
String s2 = "marA";
Assert.assertFalse(isOnePermutationOfOther(s1, s2));
}

@Test
public void isOnePermutationOfOtherGivenThatStringsContainOnlyAscii_tc1_differentlength() {
String s1 = "rama";
String s2 = "mar";
Assert.assertFalse(isOnePermutationOfOtherGivenThatStringsContainOnlyAscii(s1, s2));
}

@Test
public void isOnePermutationOfOtherGivenThatStringsContainOnlyAscii_tc2_isPermutation() {
String s1 = "ram";
String s2 = "mar";
Assert.assertTrue(isOnePermutationOfOtherGivenThatStringsContainOnlyAscii(s1, s2));
}

@Test
public void isOnePermutationOfOtherGivenThatStringsContainOnlyAscii_tc3_notPermutation() {
String s1 = "rama";
String s2 = "marA";
Assert.assertFalse(isOnePermutationOfOtherGivenThatStringsContainOnlyAscii(s1, s2));
}

public static void main(String[] args) {
System.out.println(isOnePermutationOfOther("ram", "mar"));
51 changes: 51 additions & 0 deletions src/main/java/com/ctci/arraysandstrings/IsUnique.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.ctci.arraysandstrings;

import org.junit.Assert;
import org.junit.Test;

/**
* @author rampatra
* @since 18/11/2018
@@ -32,6 +35,54 @@ private static boolean hasAllUniqueCharactersWhenStringContainsAllLowercase(Stri
return true;
}

@Test
public void hasAllUniqueCharacters_tc1_null() {
String s = null;
Assert.assertFalse(hasAllUniqueCharacters(s));
}

@Test
public void hasAllUniqueCharacters_tc2_greaterThan128() {
String s = "Currently, each country has its own language, its own characters. Extended ASCII encoding was born with the goal of being diverse in that language";
Assert.assertFalse(hasAllUniqueCharacters(s));
}

@Test
public void hasAllUniqueCharacters_tc3_notUnique() {
String s = "rama";
Assert.assertFalse(hasAllUniqueCharacters(s));
}

@Test
public void hasAllUniqueCharacters_tc4_Unique() {
String s = "ram";
Assert.assertTrue(hasAllUniqueCharacters(s));
}

@Test
public void hasAllUniqueCharacters_tc5_UniqueWithCapital() {
String s = "ramA";
Assert.assertTrue(hasAllUniqueCharacters(s));
}

@Test
public void hasAllUniqueCharactersWhenStringContainsAllLowercase_tc1_notUnique() {
String s = "rama";
Assert.assertFalse(hasAllUniqueCharactersWhenStringContainsAllLowercase(s));
}

@Test
public void hasAllUniqueCharactersWhenStringContainsAllLowercase_tc2_Unique() {
String s = "ram";
Assert.assertTrue(hasAllUniqueCharactersWhenStringContainsAllLowercase(s));
}

@Test
public void hasAllUniqueCharactersWhenStringContainsAllLowercase_tc3_UniqueWithCapital() {
String s = "ramA";
Assert.assertFalse(hasAllUniqueCharactersWhenStringContainsAllLowercase(s));
}

public static void main(String[] args) {
String s = "ram";
System.out.println(hasAllUniqueCharacters(s));