SWEN-250

C++ TDD & REGEX

Overview

This exercise requires you to write C++ code that will introduce the concept of Test Driven Development and the use of regular expressions

In this exercise you will create the rules for a simple version of a password game inspired by The Password Game by Neal Agarwal

You will be responsible for writing to rules.cpp, rules.h, and testRules.cpp

An Activity Journal is required for this activity, be sure to work on it as you go.

Be sure to reference the regex slides and the online regex tester in working on your implementations. Some of these are more challenging than they appear. Be sure to ask for help as you need it.

Requirements

  • Implement the following rules for the password game. Note that some of these rules have additional requirements.
    1. The password must be at least 8 characters in length.
    2. The password must contain at least 2 capital letters. You must make use of regex in your solution.
    3. The password must contain at least 1 special character. You must make use of regex in your solution.
    4. The password cannot contain a palindrome. For example "racecar" should not be allowed. This rule should be performed case insensitive.
    5. The password must contain within it the letters 'r', 'i', and 't'. They can be in any order. They can be spread out within the password. This should be case insensitive
    6. The password must start and end with a number. You must make use of regex in your solution.
    7. The password cannot contain '_' or '-'. You must make use of regex in your solution.
    8. The password must contain at least 4 vowels (a,e,i,o,u). You must make use of regex in your solution. This should be case insensitive
    9. At least one digit in the password must be prime. You must make use of regex in your solution.
    10. All digits in the string must sum to an even number.
  • A failure of any rule should result in the function returning an error string. Each rule's error message is below. 'X' indicate the value is to be filled by you in implementation.
    1. Passwords must be 8 characters long. Your password is X characters long.
    2. Passwords require at least 2 capital letters. Your password contains X capital letters.
    3. Passwords require at least 1 special character.
    4. Passwords cannot be a palindrome.
    5. Passwords must contain r, i, and t. Your password is missing X of these.
      • X should be a count of how many of these letters are missing.
    6. Passwords must start with a number
    7. Password cannot contain '_' or '-'. Your password contains X illegal characters.
      • X should be a count of how many of these illegal characters are present.
    8. Password must contain at least 4 vowels (a,e,i,o,u). Your password contains X vowels.
    9. Passwords require at least 1 prime digit.
    10. Passwords require that all digits sum to an even number. Your password's digits currently sum to X
  • A successful check of a rule should return an empty string "".
  • For each rule, you must implement necessary unit tests, stub the function so the program can compile, commit your work, then implement code to pass the tests and commit agian.
  • Once you have working code, add the rule to the evaluateAllRules function. This is what the main program uses to test a password

Instructions
  1. Download the zipfile:
  2. cpp_passwords.zip.
  3. Unzip the file into your repo, so that the folder name is cpp_passwords.
  4. Build the application passwords and the application test with make.
  5. Run unit tests with ./test .
  6. Examine the source code provided across all files to familiarize yourself with the application.
  7. For the current Rule, create tests in the unitTests function to confirm that future code works as expected. Ensure you test both passing and failing conditions
  8. For the current Rule, add the corresponding function to rules.h and add a stub to rules.cpp.
  9. Create a commit before proceeding to demonstrate following of TDD principals.
  10. Implement the required code to pass the tests.
  11. Add the function call to the evaluateAllRules function.
  12. Test the main application manually by running ./passwords.
  13. Update the Activity Journal.
  14. Commit your work.
  15. Repeat the testing and implementation process for each rule.
  16. When finished, be sure to push your finished work to GitLab.
The Rule Functions

The rule functions themselves should return and empty string for passing the rule and the specified error string for failing

Your test functions should compare the returned string to what is expected given your input

The provided stub for ruleLength will likely cause any tests you write to crash instead of fail during the first stage of TDD, so determine a string that will cause all your tests to fail instead of crash

Submission
  • Submit your code to a directory named cpp_passwords in your git repository.
  • Grading scheme: 100 points

    • Submission Correct: ActivityJournal.txt, rules.h, rules.cpp, testRules.cpp (5)
    • Clean build with no errors or warnings (5)
    • Activity Journal is filled out and is of sufficient quality (10)
    • Rules implemented (80 - 8 Per Rule)
      • TDD Process Followed (1)
      • Rule Added to evaluateAllRules (1)
      • Test(s) correctly evaluate functionality (2)
      • Implementation is correct and meets requirements(4)