Skip to content

GitLab

  • Menu
    • Projects Groups Snippets
      Help
Projects Groups Snippets
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in
  • P project01
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 0
    • Issues 0
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 0
    • Merge requests 0
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Packages & Registries
    • Packages & Registries
    • Package Registry
    • Infrastructure Registry
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • cs2-20wi
  • project01
  • Merge requests
  • !1

An error occurred while fetching the assigned milestone of the selected merge_request.
Merged
Created 5 years ago by Archie Shahidullah@archie:expressionless:Developer

Update CaesarCipherSolverTests.java

  • Overview 9
  • Commits 2
  • Pipelines 2
  • Changes 1
All threads resolved

Closes #1, #2, #3

Updated tests for project 1

Edited 5 years ago by Archie Shahidullah
  • Adam Blank @blank approved this merge request 5 years ago

    approved this merge request

  • Adam Blank @blank unapproved this merge request 5 years ago

    unapproved this merge request

  • Adam Blank @blank assigned to @eordentl 5 years ago

    assigned to @eordentl

  • Ethan Ordentlich
    Ethan Ordentlich @eordentl started a thread on an outdated change in commit ba4f6404 5 years ago
    Resolved by Archie Shahidullah 5 years ago
  • Archie Shahidullah :expressionless: @archie added 1 commit 5 years ago

    added 1 commit

    • 62ea5bed - Update CaesarCipherSolverTests.java

    Compare with previous version

  • Archie Shahidullah :expressionless: @archie resolved all threads 5 years ago

    resolved all threads

    • Archie Shahidullah
      Archie Shahidullah :expressionless: @archie · 5 years ago
      Author Developer
      Resolved by Ethan Ordentlich 5 years ago

      I have methods to ban the non-modified and protected fields, but just to make sure, that isn't necessary for project one right, just two and beyond?

    • Ethan Ordentlich
      Last reply by Ethan Ordentlich 5 years ago
  • Ethan Ordentlich
    Ethan Ordentlich @eordentl · 5 years ago
    Maintainer

    I mentioned this in the other MR too, but let's also add the issues this fixes to the description. See https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically.

  • Archie Shahidullah :expressionless: @archie changed the description 5 years ago

    changed the description

  • Ethan Ordentlich
    Ethan Ordentlich @eordentl · 5 years ago
    Maintainer

    LGTM - @blank?

  • Adam Blank
    Adam Blank @blank · 5 years ago
    Owner

    :thumbsup:

  • Ethan Ordentlich @eordentl resolved all threads 5 years ago

    resolved all threads

  • Ethan Ordentlich @eordentl mentioned in commit 4fad47d3 5 years ago

    mentioned in commit 4fad47d3

  • Ethan Ordentlich @eordentl merged 5 years ago

    merged

  • You're only seeing other activity in the feed. To add a comment, switch to one of the following options.
Please register or sign in to reply
Compare
  • version 1
    ba4f6404
    5 years ago

  • master (base)

and
  • latest version
    62ea5bed
    2 commits, 5 years ago

  • version 1
    ba4f6404
    1 commit, 5 years ago

1 file
+ 88
- 60

    Preferences

    File browser
    Compare changes
tests/edu/caltech/cs2/project01/CaesarCipherSolverTests.java
+ 88
- 60
  • View file @ ba4f6404

  • Edit in single-file editor

  • Edit in Web IDE


Show all unchanged lines Show 20 lines
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertIterableEquals;
import static org.junit.jupiter.params.provider.Arguments.arguments;
import edu.caltech.cs2.helpers.Inspection;
import org.junit.jupiter.api.*;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.jupiter.params.provider.ValueSource;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.Arrays;
import java.util.List;
import java.util.ArrayList;
Show 20 lines Show all unchanged lines Show 20 lines
import java.io.FileDescriptor;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.util.stream.Stream;
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
class CaesarCipherSolverTests {
String STRING_SOURCE = "src/edu/caltech/cs2/project01/CaesarCipherSolver.java";
static final String DECLARATION = "WHEN IN THE COURSE OF HUMAN EVENTS IT BECOMES NECESSARY FOR ONE PEOPLE TO DISSOLVE THE " +
"POLITICAL BANDS WHICH HAVE CONNECTED THEM WITH ANOTHER AND TO ASSUME AMONG THE POWERS OF THE EARTH THE " +
"SEPARATE AND EQUAL STATION TO WHICH THE LAWS OF NATURE AND OF NATURES GOD ENTITLE THEM A DECENT RESPECT TO " +
"THE OPINIONS OF MANKIND REQUIRES THAT THEY SHOULD DECLARE THE CAUSES WHICH IMPEL THEM TO THE SEPARATION";
static final String CONSTITUTION = "WE THE PEOPLE OF THE UNITED STATES IN ORDER TO FORM A MORE PERFECT UNION ESTABLISH " +
"JUSTICE INSURE DOMESTIC TRANQUILITY PROVIDE FOR THE COMMON DEFENCE PROMOTE THE GENERAL WELFARE AND SECURE " +
"THE BLESSINGS OF LIBERTY TO OURSELVES AND OUR POSTERITY DO ORDAIN AND ESTABLISH THIS CONSTITUTION FOR THE " +
"UNITED STATES OF AMERICA";
@Order(0)
@Tag("C")
@DisplayName("Test no usage of split(), join(), contains()")
@DisplayName("Test no usage of split(), join(), contains(), indexOf()")
@Test
public void testNoUsageOfBannedMethods() {
List<String> regexps = List.of("\\.split\\(.*?\\)", "\\.join\\(.*?\\)", "\\.contains\\(.*?\\)");
List<String> regexps = List.of("\\.split\\(.*?\\)", "\\.join\\(.*?\\)", "\\.contains\\(.*?\\)",
"\\.indexOf\\(.*?\\)");
Inspection.assertNoUsageOf(STRING_SOURCE, regexps);
}
Show 20 lines Show all unchanged lines Show 20 lines
@Tag("C")
@ParameterizedTest
@DisplayName("Test splitBySpaces(String)")
@ValueSource(strings = { "", "HI", "HI THERE", "A B C D E F GGG" })
@ValueSource(strings = { "", "HI", "HI THERE", "A B C D E F GGG", "TRUTH IS NOT A DEMOCRACY", DECLARATION})
public void testSplitBySpaces(String toSplit) {
List<String> list = CaesarCipherSolver.splitBySpaces(toSplit);
user avatar user avatar user avatar +2
assertEquals(toSplit.trim(), String.join(" ", list));
Show 20 lines Show all unchanged lines Show 20 lines
@Order(8)
@Tag("C")
@DisplayName("Test putTogetherWithSpaces([\"ABCD\"])")
@Test
public void testPutTogetherWithSpacesSingleton() {
@ParameterizedTest
@DisplayName("Test putTogetherWithSpaces(String)")
@ValueSource(strings = {"ABCD", "NEXUS", "RIVIERA"})
public void testPutTogetherWithSpacesSingleton(String toPutTogether) {
List<String> input = new ArrayList<>();
input.add("ABCD");
Assertions.assertEquals("ABCD", CaesarCipherSolver.putTogetherWithSpaces(input));
input.add(toPutTogether);
Assertions.assertEquals(toPutTogether, CaesarCipherSolver.putTogetherWithSpaces(input));
}
private static Stream<Arguments> putArgumentsStream() {
return Stream.of(
Arguments.of((Object) new String[] {"ABCD", "DDDD"}),
Arguments.of((Object) new String[] {"ONE", "BY", "LAND", "TWO", "BY", "SEA"}),
Arguments.of((Object) CONSTITUTION.split(" "))
);
}
@Order(9)
@Tag("C")
@DisplayName("Test putTogetherWithSpaces([\"ABCD\", \"DDDD\"])")
@Test
public void testPutTogetherWithSpaces() {
List<String> input = new ArrayList<>();
input.add("ABCD");
input.add("DDDD");
Assertions.assertEquals("ABCD DDDD", CaesarCipherSolver.putTogetherWithSpaces(input));
@ParameterizedTest
@DisplayName("Test putTogetherWithSpaces()")
@MethodSource("putArgumentsStream")
public void testPutTogetherWithSpaces(String[] strings) {
List<String> input = Arrays.asList(strings);
Assertions.assertEquals(String.join(" ", input), CaesarCipherSolver.putTogetherWithSpaces(input));
}
@Order(10)
@Tag("C")
@DisplayName("Test howManyWordsIn([\"ABCD\", \"DDDD\"], [])")
@Test
public void testHowManyWordsInEmpty() {
List<String> dictionary = new ArrayList<>();
List<String> sentence = new ArrayList<>();
sentence.add(new String("ABCD"));
sentence.add(new String("DDDD"));
Assertions.assertEquals(0, CaesarCipherSolver.howManyWordsIn(sentence, dictionary));
private static Stream<Arguments> howArgumentsStream() {
return Stream.of(
arguments(new String[] {""}, new String[] {"ABCD", "DDDD"}, 0),
arguments(new String[] {"ABCD"}, new String[] {"ABCD", "DDDD"}, 1),
arguments(new String[] {"ABCD", "EFGH"}, new String[] {"ABCD", "ABCD", "NOT"}, 2),
// DECLARATION but with duplicate words removed
arguments(new String[] {"WHEN", "IN", "THE", "COURSE", "OF", "HUMAN", "EVENTS", "IT", "BECOMES",
"NECESSARY", "FOR", "ONE", "PEOPLE", "TO", "DISSOLVE", "POLITICAL", "BANDS", "WHICH",
"HAVE", "CONNECTED", "THEM", "WITH", "ANOTHER", "AND", "ASSUME", "AMONG", "POWERS",
"EARTH", "SEPARATE", "EQUAL", "STATION", "LAWS", "NATURE", "NATURES", "GOD", "ENTITLE",
"A", "DECENT", "RESPECT", "OPINIONS", "MANKIND", "REQUIRES", "THAT", "THEY", "SHOULD",
"DECLARE", "CAUSES", "IMPEL", "SEPARATION"},
CONSTITUTION.split(" "), 19)
);
}
@Order(11)
@Order(10)
@Tag("C")
@DisplayName("Test howManyWordsIn([\"ABCD\", \"DDDD\"], [\"ABCD\"])")
@Test
public void testHowManyWordsInSingleton() {
List<String> dictionary = new ArrayList<>();
dictionary.add(new String("ABCD"));
List<String> sentence = new ArrayList<>();
sentence.add(new String("ABCD"));
sentence.add(new String("DDDD"));
Assertions.assertEquals(1, CaesarCipherSolver.howManyWordsIn(sentence, dictionary));
@ParameterizedTest
@DisplayName("Test howManyWordsIn")
@MethodSource("howArgumentsStream")
public void testHowManyWords(String[] dict, String[] sent, int same) {
List<String> dictionary = Arrays.asList(dict);
List<String> sentence = Arrays.asList(sent);
Assertions.assertEquals(same, CaesarCipherSolver.howManyWordsIn(sentence, dictionary));
}
@Order(12)
@Tag("C")
@DisplayName("Test howManyWordsIn([\"ABCD\", \"ABCD\", \"NOT\"], [\"ABCD\", \"EFGH\"])")
@Test
public void testHowManyWordsWithDuplicates() {
List<String> dictionary = new ArrayList<>();
dictionary.add(new String("ABCD"));
dictionary.add(new String("EFGH"));
List<String> sentence = new ArrayList<>();
sentence.add(new String("ABCD"));
sentence.add(new String("ABCD"));
sentence.add(new String("NOT"));
Assertions.assertEquals(2, CaesarCipherSolver.howManyWordsIn(sentence, dictionary));
private static Stream<Arguments> mainArgumentsStream() {
return Stream.of(
arguments("HELLO", new String[] {"HELLO"}),
arguments("FYYFHP FY IFBS", new String[] {"ATTACK AT DAWN"}),
arguments("AI NYUG", new String[] {"GO TEAM"}),
arguments("NK", new String[] {"BY", "HE", "IF"}),
arguments("EH", new String[] {"OR", "BE"}),
arguments("BO", new String[] {"RE", "AN"}),
// Stress tests
arguments("DOLU PU AOL JVBYZL VM OBTHU LCLUAZ PA ILJVTLZ ULJLZZHYF MVY VUL WLVWSL AV KPZZVSCL AOL " +
"WVSPAPJHS IHUKZ DOPJO OHCL JVUULJALK AOLT DPAO HUVAOLY HUK AV HZZBTL HTVUN AOL WVDLYZ VM AOL " +
"LHYAO AOL ZLWHYHAL HUK LXBHS ZAHAPVU AV DOPJO AOL SHDZ VM UHABYL HUK VM UHABYLZ NVK LUAPASL " +
"AOLT H KLJLUA YLZWLJA AV AOL VWPUPVUZ VM THURPUK YLXBPYLZ AOHA AOLF ZOVBSK KLJSHYL AOL JHBZLZ " +
"DOPJO PTWLS AOLT AV AOL ZLWHYHAPVU", new String[] {DECLARATION}),
arguments("RZ OCZ KZJKGZ JA OCZ PIDOZY NOVOZN DI JMYZM OJ AJMH V HJMZ KZMAZXO PIDJI ZNOVWGDNC EPNODXZ " +
"DINPMZ YJHZNODX OMVILPDGDOT KMJQDYZ AJM OCZ XJHHJI YZAZIXZ KMJHJOZ OCZ BZIZMVG RZGAVMZ VIY " +
"NZXPMZ OCZ WGZNNDIBN JA GDWZMOT OJ JPMNZGQZN VIY JPM KJNOZMDOT YJ JMYVDI VIY ZNOVWGDNC OCDN " +
"XJINODOPODJI AJM OCZ PIDOZY NOVOZN JA VHZMDXV", new String[] {CONSTITUTION})
);
}
@Order(13)
@Order(11)
@Tag("C")
@ParameterizedTest
@DisplayName("Test main()")
@CsvSource({
"HELLO, HELLO",
"FYYFHP FY IFBS, ATTACK AT DAWN",
"AI NYUG, GO TEAM"
})
public void testMain(String cipher, String expected) {
@MethodSource("mainArgumentsStream")
public void testMain(String cipher, String[] expected) {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
System.setOut(new PrintStream(outputStream));
byte[] input = cipher.getBytes();
InputStream fakeIn = new ByteArrayInputStream(input);
System.setIn(fakeIn);
Show 20 lines Show all unchanged lines Show 20 lines
System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out)));
String output = outputStream.toString();
System.out.print(output);
assertEquals("Type a sentence to decrypt: " + expected + "\n", output.replaceAll("\r\n", "\n"));
assertEquals("Type a sentence to decrypt: " + String.join("\n", expected) +
"\n", output.replaceAll("\r\n", "\n"));
}
}
\ No newline at end of file
Assignee
Ethan Ordentlich's avatar
Ethan Ordentlich
@eordentl
Assign to
0 Reviewers
None
Request review from
Milestone
No milestone
None
None
Time tracking
No estimate or time spent
Labels
0
None
0
None
    Assign labels
  • Manage project labels

Lock merge request
Unlocked
0
0 participants
Reference:
Source branch: tests

Menu

Projects Groups Snippets
Help