Skip to content

GitLab

  • Menu
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-22wi
  • project01
  • Issues
  • #1

Closed
Open
Created Jan 08, 2022 by James C Bowden@jbowdenOwner

random constructor not thoroughly tested

This is inspired by this chunk of code, which works until the last tests for student. Barron reported.

public SubstitutionCipher(String ciphertext) {
        this.ciphertext = ciphertext;
        HashMap<Character, Character> key = new HashMap<Character, Character>();

        for (char c : ciphertext.toCharArray()) {
            key.putIfAbsent(c, c);
        }
        this.key = key;

        for (int i = 0; i < 10000; i++) {
            this.key = randomSwap().key;
        }
    }

I think they can get away with this because the test case for randomswap has long ciphertext and thus most letters actually get added in. Could fix by making an explicit case with a smaller ciphertext such that randomswap should hit an NPE or something of the sort relatively quickly from trying to get a letter that never actually got added to the key.

Edited Jan 08, 2022 by James C Bowden
Assignee
Assign to
Time tracking