Welcome!
The questions below are about code comprehension and testing, and will be the only non-behavioral phase of the interview process.
Good luck! 😄
Given the following code, answer the questions below.
function add(numbers: string): number {
let integers = numbers.split(',').map(x => parseInt(x));
let negatives = integers.filter(x => x < 0);
if (negatives.length > 0)
throw new RangeError('Negatives are not allowed: ' + negatives.join(', '));
return integers
.filter(x => x <= 1000)
.reduce((a, b) => a + b, 0);
}
let result = add('1, 2, 4, 5');
console.log(result);
-
What does this code do?
-
What kind of test would be good to test this functionality and why?
-
What might that test look like?
Given the following code, answer the questions below.
import time
def compute(x):
response = expensive_api_call()
return response + x
def expensive_api_call():
time.sleep(1000) # takes 1,000 seconds to run
return 123
def test_compute():
expected = 124
actual = compute(1)
assert expected == actual
-
What does the test in this code do?
-
What is the problem with the test and how could it be resolved?
-
Assume the code was kept as is. If it relies on a call to an API available on the same machine that must be present for the test to run, what would you call this kind of test?
-
Assume the code was kept as is. Would this test be a better candidate for running on a local machine or in a continuous integration pipeline and why?
// This is using the `Cypress` framework
describe('Find author at articles.com', () => {
beforeEach(() => {
cy.visit('/');
});
it('Find the author Steve Austin', () => {
cy.get('#js-search-input').type('Steve Austin');
cy.get('h2 > a').first().click();
cy.get('.author-post__author-title').click();
cy.contains('.author__title', 'Steve Austin').should('be.visible');
});
});
-
What does the test in this code do?
-
What kind of test is this considered?