Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task6 #91

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.DS_Store
.DS_Store
/node_modules
5 changes: 5 additions & 0 deletions __tests__/sum.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// sum.test.js

test('adds 1 + 2 to equal 3', () => {
// TODO
});
11 changes: 11 additions & 0 deletions __tests__/unit.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// unit.test.js

import {
isPhoneNumber,
isEmail,
isStrongPassword,
isDate,
isHexColor,
} from '../code-to-unit-test/unit-test-me';

// TODO - Part 2
3 changes: 3 additions & 0 deletions code-to-unit-test/sum.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function sum(a, b) {
return a + b;
}
32 changes: 32 additions & 0 deletions code-to-unit-test/unit-test-me.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// matches valid phone numbers
export function isPhoneNumber(phoneNumber) {
const phoneRegex = /((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}/;
return phoneRegex.test(phoneNumber);
}

// matches valid emails
export function isEmail(email) {
const emailRegex = /^\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,3}$/;
return emailRegex.test(email);
}

/**
* The password's first character must be a letter, it must contain at least * 4 characters and no more than 15 characters and no characters other than * * letters, numbers and the underscore may be used
*/
export function isStrongPassword(password) {
const pwRegex = /^[a-zA-Z]\w{3,14}$/;
return pwRegex.test(password);
}

// This regular expressions matches dates of the form XX / XX / YYYY where
// XX can be 1 or 2 digits long and YYYY is always 4 digits long.
export function isDate(date) {
const dateRegex = /^\d{1,2}\/\d{1,2}\/\d{4}$/;
return dateRegex.test(date);
}

// Matches valid 3 or 6 character hex codes used for HTML or CSS.
export function isHexColor(color) {
const colorRegex = /^\#?[A-Fa-f0-9]{3}([A-Fa-f0-9]{3})?$/;
return colorRegex.test(color);
}
Loading