Skip to content

Commit

Permalink
setting up challenge
Browse files Browse the repository at this point in the history
  • Loading branch information
doublederek committed Apr 25, 2024
0 parents commit 78e3943
Show file tree
Hide file tree
Showing 28 changed files with 326 additions and 0 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: PR Tests

on:
pull_request:
branches:
- main
paths:
- 'go/**'

jobs:
go-tests:
name: Run Go Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- id: changes
uses: jitterbit/get-changed-files@v1

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: '1.21.5' # Specify your Go version here

- name: Set Environment Variable
run: echo "TEST_ANSWER=${{ secrets.TEST_ANSWER }}" >> $GITHUB_ENV

- name: Run Go Tests
run: cd go && go test ./...
25 changes: 25 additions & 0 deletions .github/workflows/javascript.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: PR Tests

on:
pull_request:
branches:
- main
paths:
- 'javascript/**'

jobs:
javascript-tests:
name: Run JavaScript Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- id: changes
uses: jitterbit/get-changed-files@v1
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '14'
- name: Set Environment Variable
run: echo "TEST_ANSWER=${{ secrets.TEST_ANSWER }}" >> $GITHUB_ENV
- run: cd javascript && npm install
- run: cd javascript && npm test
31 changes: 31 additions & 0 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: PR Tests

on:
pull_request:
branches:
- main
paths:
- 'python/**'

jobs:
python-tests:
name: Run Python Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- id: changes
uses: jitterbit/get-changed-files@v1

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.8' # Specify the Python version here

- name: Set Environment Variable
run: echo "TEST_ANSWER=${{ secrets.TEST_ANSWER }}" >> $GITHUB_ENV

- name: Run Python Tests
run: |
cd python
python3 solution.test.py
28 changes: 28 additions & 0 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: PR Tests

on:
pull_request:
branches:
- main
paths:
- 'ruby/**'

jobs:
ruby-tests:
name: Run Ruby Tests
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v2

- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.0'
bundler-cache: true

- name: Set Environment Variable
run: echo "TEST_ANSWER=${{ secrets.TEST_ANSWER }}" >> $GITHUB_ENV

- run: cd ruby && bundle install
- run: cd ruby && rspec solution.test.rb
36 changes: 36 additions & 0 deletions .github/workflows/typescript.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: PR Tests

on:
pull_request:
branches:
- main
paths:
- 'typescript/**'

jobs:
typescript-tests:
name: Run TypeScript Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- id: changes
uses: jitterbit/get-changed-files@v1

- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '14'

- name: Set Environment Variable
run: echo "TEST_ANSWER=${{ secrets.TEST_ANSWER }}" >> $GITHUB_ENV

- name: Install dependencies
run: |
cd typescript
npm install
- name: Run TypeScript Tests
run: |
cd typescript
npm test
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
package-lock.json
Gemfile.lock
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"cSpell.words": [
"Thematics"
]
}
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Engineering Internship
## Technical Assessment Challenge

### Playfair Cipher Solver

#### Challenge
Your goal is to build an application that can solve a Playfair Cipher. To learn more about Playfair Ciphers and how they are constructed, consult the following Wikipedia page on the subject: [https://en.wikipedia.org/wiki/Playfair_cipher](https://en.wikipedia.org/wiki/Playfair_cipher).

Ideally this challenge should be able to be completed in 3 hours or less. You may choose one of the 5 following programming languages to complete this challenge:
- Ruby
- JavaScript
- TypeScript
- Python
- Go

Ensure your code is properly commented and formatted for readability and ease-of-understanding.

#### Thematics
*"Attention spy network! You've been assigned a task of the utmost importance! We've received an encrypted message from an agent in the field containing the password to a top secret club for super spies. The encrypted message reads as follows: **"IKEWENENXLNQLPZSLERUMRHEERYBOFNEINCHCV"**. We've been told if we can crack this code and give the password to the door-person at the corner of 32nd Street, we will gain access to the illustrious spy club **Spy City**! We must get inside! However the password has been encrypted with an older system known as a **Playfair Cipher**. Our agent in the field says the key to the cipher is the string **"SUPERSPIES"**. However, for the life of us we cannot crack this code! Devise an application that can solve this encryption, get the password, and join us inside Spy City for what we are sure will be a night to remember!"*

#### Instructions
1. Fork this repo to your personal Github account.
2. Clone your forked repo to begin working on the challenge locally.
3. Create a new Branch in your repo where you will be pushing your code to.
4. Choose which programming language you wish to complete the challenge with.
- Navigate to the folder of that programming language and complete your work in the `solution` file found inside. ie: `ruby/solution.rb`
- **Do not** edit the test file in the folder. Tests will only work as intended after you have submitted a PR.
- You'll find a separate `README.md` in that folder with language specific instructions.
5. Ensure your application is executable from the command-line by running your `solution` file.
6. Your decrypted string must by entirely **UPPER CASE**, and not include `spaces`, the letter `"X"`, or `special characters`. Ensure you meet all these conditions before outputting the result.
7. Your application must output ***only*** the decrypted Playfair Cipher string.
- ie: `BANANAS` ***not*** `The decrypted text is: BANANAS`

#### Submission
Upon completion of the challenge, create a PR of your work and compare it against the original Assessment Repo's `main` branch. Submit a link to your PR with your internship application in the appropriate field.

This repo is designed to run a test against your work to ensure the correct decrypted string is outputted to the console when executing your code. Admins on this repo will deploy the test manually only after you have submitted your PR.
3 changes: 3 additions & 0 deletions go/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Go Instructions

- Ensure your code can run in the command-line with the command `go run solution.go`
3 changes: 3 additions & 0 deletions go/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module solution

go 1.21.5
1 change: 1 addition & 0 deletions go/solution.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package main
24 changes: 24 additions & 0 deletions go/solution_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package main

import (
"os"
"os/exec"
"strings"
"testing"
)

func TestSolutionOutput(t *testing.T) {
cmd := exec.Command("go", "run", "solution.go")
outputBytes, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("Failed to run the command: %v", err)
}

// Trim space from output and expected value
output := strings.TrimSpace(string(outputBytes))
expected := strings.TrimSpace(os.Getenv("TEST_ANSWER"))

if output != expected {
t.Errorf("Unexpected output, got: %q, want: %q", output, expected)
}
}
4 changes: 4 additions & 0 deletions javascript/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# JavaScript Instructions

- Install all dependencies with the command `npm install`
- Ensure your code can run in the command-line with the command `node solution.js`
14 changes: 14 additions & 0 deletions javascript/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "javascript",
"version": "1.0.0",
"description": "",
"main": "solution.js",
"scripts": {
"test": "jest"
},
"author": "",
"license": "ISC",
"dependencies": {
"jest": "^29.7.0"
}
}
Empty file added javascript/solution.js
Empty file.
12 changes: 12 additions & 0 deletions javascript/solution.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const { exec } = require("child_process");

describe('solution.js script', () => {
it('should output correct answer to the console', (done) => {
exec("node solution.js", (error, stdout, stderr) => {
expect(error).toBeNull();
expect(stderr).toBe("");
expect(stdout.trim()).toBe(process.env.TEST_ANSWER); // trim to remove any extra newlines that console.log might generate
done(); // indicate that this async test is complete
});
});
});
3 changes: 3 additions & 0 deletions python/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Python Instructions

- Ensure your code can run in the command-line with the command `python3 solution.py`
Empty file added python/solution.py
Empty file.
15 changes: 15 additions & 0 deletions python/solution.test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import unittest
import subprocess
import os

class TestSolution(unittest.TestCase):
def test_decryption_output(self):
# Run the solution.py script
result = subprocess.run(['python3', 'solution.py'], text=True, capture_output=True)

# Check the output
expected_output = os.getenv('TEST_ANSWER')
self.assertEqual(result.stdout.strip(), expected_output)

if __name__ == '__main__':
unittest.main()
3 changes: 3 additions & 0 deletions ruby/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source "https://rubygems.org"

gem "rspec"
3 changes: 3 additions & 0 deletions ruby/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Ruby Instructions

- Ensure your code can run in the command-line with the command `ruby solution.rb`
Empty file added ruby/solution.rb
Empty file.
6 changes: 6 additions & 0 deletions ruby/solution.test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
RSpec.describe 'Playfair Decryption Script' do
it 'outputs the correct decrypted text' do
output = `ruby solution.rb` # Using backticks to execute the script and capture the output.
expect(output.strip).to eq(ENV['TEST_ANSWER']) # Compares the stripped output to the expected string.
end
end
4 changes: 4 additions & 0 deletions typescript/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# TypeScript Instructions

- Install all dependencies with the command `npm install`
- Ensure your code can run in the command-line with the command `ts-node solution.ts` or `npx ts-node solution.ts`
4 changes: 4 additions & 0 deletions typescript/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
};
20 changes: 20 additions & 0 deletions typescript/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "typescript",
"version": "1.0.0",
"description": "",
"main": "solution.js",
"scripts": {
"test": "jest"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@types/jest": "^29.5.12",
"@types/node": "^20.12.7",
"jest": "^29.7.0",
"ts-jest": "^29.1.2",
"ts-node": "^10.9.2",
"typescript": "^5.4.5"
}
}
13 changes: 13 additions & 0 deletions typescript/solution.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { exec } from 'child_process';
import { promisify } from 'util';

const execAsync = promisify(exec);

describe('solution.ts output', () => {
it('should print the correct output to the console', async () => {
const { stdout } = await execAsync('ts-node solution.ts');

const expected = process.env.TEST_ANSWER;
expect(stdout.trim()).toBe(expected);
});
});
Empty file added typescript/solution.ts
Empty file.

0 comments on commit 78e3943

Please sign in to comment.