Skip to content

Commit

Permalink
Create HelloWorld test program
Browse files Browse the repository at this point in the history
  • Loading branch information
alvinsng committed Jan 7, 2021
1 parent 835e5e0 commit edd3307
Show file tree
Hide file tree
Showing 21 changed files with 978 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
target/
node_modules/
__pycache__/
.pytest_cache/
.DS_Store
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,16 @@
# public-interview
Public interview files for candidates
# Brex Eng Debugging Interview Sample
This "Hello World" program is provided for upcoming Brex candidates to verify their local development setup works before their debugging interview.

## Languages
We currently support 3 programming languages (Java, Python & Javascript) for this interview. You should pick the language you are most comfortable with. For each language folder, you'll find a README.md with setup instructions on how to install the necessary programs to run the code. You will be allowed to lookup online documentation for help on language syntax during the interview.

## The "Hello World" program
The "Hello World" program reads a file and returns it to caller. The program will has 2 unit tests (1 passing, 1 failing). You should check that both unit tests run and that you're able to fix the 2nd unit test.

## Preparing for your interview
On the day of your interview, your interviewer will be sending you a zip file that contains the code for the buggy program. You'll be using your own computer to run the program and fix it. You may use any text editor or IDE to assist in solving the bugs. You can add print statements or change the code to help with finding the bug.

You can also use a debugger as well to set breakpoints to further debug the program. However, it is not recommended to use a debugger if you're new to it. The program can be solved with just using print statements.

## Questions
If you have any other questions about this interview, feel free to reach out to your recruiter.
24 changes: 24 additions & 0 deletions eng-debugging/hello_world_java/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
### Setup
1. If you don't have JDK 8+ installed, run `brew cask install adoptopenjdk8`/`sudo apt-get install openjdk-8-jre`/`sudo yum install java-1.8.0-openjdk-devel`. Verify using `java -version`. If you get an error `Error: Cask 'adoptopenjdk8' is unavailable: No Cask with this name exists.`, first run `brew update` followed by `brew tap adoptopenjdk/openjdk` (more on mac installation [here](https://mkyong.com/java/how-to-install-java-on-mac-osx/))
2. Install Maven using `brew install maven`/`sudo apt install maven`/`sudo yum install maven`. Verify using `mvn -version`.
3. run `mvn install` inside this folder. This will run the tests too.
4. run `mvn test` to run all unit tests.
5. You can use a Java IDE of your choice to run and debug the tests.

---------------------------------------

#### IDE/Windows-specific bugs (skip unless you're having problems on Windows or with your IDE):
Make sure you have completed setup before proceeding!

IntelliJ:
- Error: `java: package org.apache.commons.lang3 does not exist`
- Right-click `pom.xml` in the directory window > "Add as Maven Project"; this should reload the project with `org.apache.commons:commons-lang3:3.10` as a dependency now.
- Error: `java: cannot access <class>`
- File > Invalidate Caches / Restart...

Visual Studio Code/Windows:
- `JAVA_HOME` not updating
- Quit ALL VSCode windows, otherwise machine might not pick up updated `JAVA_HOME`
- VSCode Maven extension is not enough
- Install in your home subdirectory - instructions: https://maven.apache.org/install.html
- Update Windows PATH to include that subdirectory
37 changes: 37 additions & 0 deletions eng-debugging/hello_world_java/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.brexhq</groupId>
<artifactId>hello_world_java</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.10</version>
</dependency>
</dependencies>

</project>
27 changes: 27 additions & 0 deletions eng-debugging/hello_world_java/src/main/java/HelloWorld.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;

public class HelloWorld {
private final String filePath;

HelloWorld(String filePath) {
this.filePath = filePath;
}

public String loadFile() throws IOException {
URL file = this.getClass().getClassLoader().getResource(filePath);
String path = new File(file.getPath()).getAbsolutePath();
return new String(Files.readAllBytes(Paths.get(path)), StandardCharsets.UTF_8);
}

public String run() throws IOException {
String contents = loadFile();
// To fix test case 2, change the line below.
return contents.replace('_', ' ');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello world
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello_world
25 changes: 25 additions & 0 deletions eng-debugging/hello_world_java/src/test/java/HelloWorldTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import org.junit.Test;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;

import static org.junit.Assert.assertEquals;

public class HelloWorldTest {
@Test
public void testCase1() throws IOException {
// This test case is passing
HelloWorld helloWorld = new HelloWorld("input/test_1.txt");
String actualOutput = helloWorld.run();
assertEquals("hello world\n", actualOutput);
}

@Test
public void testCase2() throws IOException {
// This test case is failing
HelloWorld helloWorld = new HelloWorld("input/test_2.txt");
String actualOutput = helloWorld.run();
assertEquals("hello-world\n", actualOutput);
}
}
10 changes: 10 additions & 0 deletions eng-debugging/hello_world_javascript/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
### Setup
1. If you don't have nodejs installed, run `brew install node` for Mac. See https://nodejs.org/en/download/ for other OS
2. run `npm install` inside this folder
3. run `npm test` to run all unit tests
4. run `npm run test-only 1` to just run the first test


## Tested on
node v12.6.0
npm v6.13.2
1 change: 1 addition & 0 deletions eng-debugging/hello_world_javascript/input/test_1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello world
1 change: 1 addition & 0 deletions eng-debugging/hello_world_javascript/input/test_2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello_world
19 changes: 19 additions & 0 deletions eng-debugging/hello_world_javascript/lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const fs = require('fs');

class HelloWorld {
constructor(filePath) {
this.filePath = filePath;
}

loadFile(cb) {
return fs.readFileSync(this.filePath, 'utf8');
}

run() {
const contents = this.loadFile();
// to fix test case 2, fix line below:
return contents.replace('_', ' ');
}
}

module.exports = HelloWorld;
Loading

0 comments on commit edd3307

Please sign in to comment.