-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: refactor and added new challenges
- Loading branch information
Showing
15 changed files
with
5,354 additions
and
323 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,22 @@ | ||
/* | ||
* Somar os argumentos | ||
* Calcular o MDC | ||
*/ | ||
|
||
/* ENUNCIADO | ||
* | ||
* Você deve escrever uma função que some | ||
* todos os argumentos providos. | ||
* Você deve escrever uma função que calcula e retorna o MDC | ||
* (máximo divisor comum) entre dois números. | ||
* Para isso você pode usar as seguintes informações: | ||
* | ||
* 1. O MDC de um número N com 0 é o próprio N. | ||
* | ||
* 2. O MDC entre dois números M e N, onde M > N é | ||
* igual ao MDC de N e do resto da divisão de M por N. | ||
* | ||
* Você pode considerar que nas entradas dos testes | ||
* a > b sempre. | ||
*/ | ||
|
||
const sumArguments = arr => {} | ||
const MDC = (a, b) => {} | ||
|
||
module.exports = sumArguments | ||
module.exports = MDC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,23 @@ | ||
const sumArguments = require('./challenge') | ||
const MDC = require('./challenge') | ||
|
||
describe('Challenge 1', () => { | ||
test(`It should return 6 | ||
[INPUT]: 1, 2, 3`, () => { | ||
expect(sumArguments(1, 2, 3)).toBe(6) | ||
[INPUT]: 12, 18`, () => { | ||
expect(MDC(12, 18)).toBe(6) | ||
}) | ||
|
||
test(`It should return 14 | ||
[INPUT]: 1, 2, 10, 1`, () => { | ||
expect(sumArguments(1, 2, 10, 1)).toBe(14) | ||
test(`It should return 1 | ||
[INPUT]: 20, 33`, () => { | ||
expect(MDC(20, 33)).toBe(1) | ||
}) | ||
|
||
test(`It should return 3 | ||
[INPUT]: 1, 2, 2, -2`, () => { | ||
expect(sumArguments(1, 2, 2, -2)).toBe(3) | ||
test(`It should return 23 | ||
[INPUT]: 368, 391`, () => { | ||
expect(MDC(368, 391)).toBe(23) | ||
}) | ||
|
||
test(`It should return idwallchallenge | ||
[INPUT]: 'id', 'wall', 'challenge'`, () => { | ||
expect(sumArguments('id', 'wall', 'challenge')).toBe('idwallchallenge') | ||
}) | ||
|
||
test(`It should return javascript is fun | ||
[INPUT]: 'javascript ', 'is ', 'fun'`, () => { | ||
expect(sumArguments('javascript ', 'is ', 'fun')).toBe('javascript is fun') | ||
}) | ||
|
||
test(`It should return 8and weird | ||
[INPUT]: 1, 2, 5, 'and weird'`, () => { | ||
expect(sumArguments(1, 2, 5, 'and weird')).toBe('8and weird') | ||
test(`It should return 92 | ||
[INPUT]: 1380, 1472`, () => { | ||
expect(MDC(1380, 1472)).toBe(92) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,57 @@ | ||
/* | ||
* Números primos | ||
* Normalização de estruturas | ||
*/ | ||
|
||
/* ENUNCIADO | ||
* | ||
* Você deve fazer um programa que soma o valor de todos | ||
* os números primos existentes de 1 a n, onde n é dado como | ||
* parâmetro. | ||
* | ||
* Para isso você deve usar a função já escrita de verificação | ||
* de primalidade. | ||
* | ||
* Exemplo: | ||
* sumPrimes(15) deve retornar 41 | ||
* Você deve escrever uma função que realize a | ||
* normalização da estrutura representada pela variável input de | ||
* forma que o retorno seja compatível com a variável output | ||
* | ||
*/ | ||
|
||
const isPrime = require('../../utils/isPrime') | ||
/* | ||
* [INPUT] Object | ||
* { | ||
* "id": "6197b77e-3942-11ea-a137-2e728ce88125", | ||
* "user": { | ||
* "id": "6197ba94", | ||
* "name": "Laura" | ||
* }, | ||
* "reports": [ | ||
* { | ||
* "id": "51ddf1a9", | ||
* "result": { | ||
* "document": "356.4325-10", | ||
* "status": "em análise", | ||
* } | ||
* } | ||
* ] | ||
* } | ||
* | ||
* [OUTPUT] Object | ||
* { | ||
* "results": { | ||
* "6197b77e-3942-11ea-a137-2e728ce88125": { | ||
* id: "6197b77e-3942-11ea-a137-2e728ce88125", | ||
* user: "6197ba94", | ||
* reports: ["51ddf1a9"] | ||
* } | ||
* }, | ||
* "users": { | ||
* "6197ba94": { "id": "6197ba94", "name": "Laura" } | ||
* }, | ||
* "reports": { | ||
* "51ddf1a9": { | ||
* "id": "51ddf1a9", | ||
* "user": "6197ba94", | ||
* "document": "356.4325-10", | ||
* "status": "em análise", | ||
* } | ||
* } | ||
* } | ||
*/ | ||
|
||
const sumPrimes = n => {} | ||
const normalizeData = unormalized => {} | ||
|
||
module.exports = sumPrimes | ||
module.exports = normalizeData |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,100 @@ | ||
const sumPrimes = require('./challenge') | ||
const normalizeData = require('./challenge') | ||
|
||
describe('Challenge 2', () => { | ||
test(`It should return 41 | ||
[INPUT]: 15`, () => { | ||
expect(sumPrimes(15)).toBe(41) | ||
}) | ||
test(`It should execute normalize data with given data as example`, async () => { | ||
const unormalized = { | ||
id: '6197b77e-3942-11ea-a137-2e728ce88125', | ||
user: { | ||
id: '6197ba94', | ||
name: 'Laura', | ||
}, | ||
reports: [ | ||
{ | ||
id: '51ddf1a9', | ||
result: { | ||
document: '356.4325-10', | ||
status: 'em análise', | ||
}, | ||
}, | ||
], | ||
} | ||
|
||
const normalized = { | ||
results: { | ||
'6197b77e-3942-11ea-a137-2e728ce88125': { | ||
id: '6197b77e-3942-11ea-a137-2e728ce88125', | ||
user: '6197ba94', | ||
reports: ['51ddf1a9'], | ||
}, | ||
}, | ||
users: { | ||
'6197ba94': { id: '6197ba94', name: 'Laura' }, | ||
}, | ||
reports: { | ||
'51ddf1a9': { | ||
id: '51ddf1a9', | ||
user: '6197ba94', | ||
document: '356.4325-10', | ||
status: 'em análise', | ||
}, | ||
}, | ||
} | ||
|
||
test(`It should return 77 | ||
[INPUT]: 20`, () => { | ||
expect(sumPrimes(20)).toBe(77) | ||
expect(normalizeData(unormalized)).toEqual(normalized) | ||
}) | ||
|
||
test(`It should return 77 | ||
[INPUT]: 43`, () => { | ||
expect(sumPrimes(43)).toBe(281) | ||
test(`It should execute normalize data with two results`, async () => { | ||
const unormalized = { | ||
id: '3942-2e728ce88125-11ea-a137-a98dy12uhd', | ||
user: { | ||
id: '90013adv', | ||
name: 'Milson', | ||
}, | ||
reports: [ | ||
{ | ||
id: '512dg5f1a9', | ||
result: { | ||
document: '356.4325-10', | ||
status: 'em análise', | ||
}, | ||
}, | ||
{ | ||
id: '01223saf', | ||
result: { | ||
document: '123.09312-99', | ||
status: 'concluido', | ||
}, | ||
}, | ||
], | ||
} | ||
|
||
const normalized = { | ||
results: { | ||
'3942-2e728ce88125-11ea-a137-a98dy12uhd': { | ||
id: '3942-2e728ce88125-11ea-a137-a98dy12uhd', | ||
user: '90013adv', | ||
reports: ['512dg5f1a9', '01223saf'], | ||
}, | ||
}, | ||
users: { | ||
'90013adv': { id: '90013adv', name: 'Milson' }, | ||
}, | ||
reports: { | ||
'512dg5f1a9': { | ||
id: '512dg5f1a9', | ||
user: '90013adv', | ||
document: '356.4325-10', | ||
status: 'em análise', | ||
}, | ||
'01223saf': { | ||
id: '01223saf', | ||
user: '90013adv', | ||
document: '123.09312-99', | ||
status: 'concluido', | ||
}, | ||
}, | ||
} | ||
|
||
expect(normalizeData(unormalized)).toEqual(normalized) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,37 @@ | ||
/* | ||
* Calcular o MDC | ||
* Requisição na API e componente de Loading | ||
*/ | ||
|
||
/* ENUNCIADO | ||
* | ||
* Você deve escrever uma função que calcula e retorna o MDC | ||
* (máximo divisor comum) entre dois números. | ||
* Para isso você pode usar as seguintes informações: | ||
* Neste exercício você deverá escrever uma função que faz | ||
* uma requisição para nossa API. Em uma aplicação real, | ||
* essa função seria chamada no início da renderização de | ||
* uma página web. | ||
* Como se trata de um fluxo assíncrono, é necessário que | ||
* o usuário saiba que esses dados estão sendo carregados, | ||
* para tanto você deve ativar uma componente de | ||
* "Carregando" através da função setLoading. | ||
* | ||
* 1. O MDC de um número N com 0 é o próprio N. | ||
* Para usar essa função basta chamar em seu código: | ||
* setLoading(true), para abrir essa componente e | ||
* setLoading(false), para fechá-la. | ||
* | ||
* 2. O MDC entre dois números M e N, onde M > N é | ||
* igual ao MDC de N e do resto da divisão de M por N. | ||
* Uma vez que você obtiver os dados, você deve armazená- | ||
* los através de uma função setData. | ||
* | ||
* Em caso de erro, você deve abrir uma componente de | ||
* erro, através da função setError, que funciona analoga- | ||
* mente à função de loading. | ||
* | ||
* Para fazer a request, use nossa função chamada api, na | ||
* forma api().then()... | ||
* | ||
* Você pode considerar que nas entradas dos testes | ||
* a > b sempre. | ||
*/ | ||
|
||
const MDC = (a, b) => {} | ||
const { setData, setError, setLoading } = require('../../utils/stateHandlers') | ||
const api = require('../../utils/api') // Promise | ||
|
||
const doRequest = () => {} | ||
|
||
module.exports = MDC | ||
module.exports = doRequest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,27 @@ | ||
const MDC = require('./challenge') | ||
const doRequest = require('./challenge') | ||
const api = require('../../utils/api') | ||
|
||
jest.mock('../../utils/stateHandlers', () => { | ||
return { | ||
setError: jest.fn(() => null), | ||
setLoading: jest.fn(() => null), | ||
setData: jest.fn(() => null), | ||
} | ||
}) | ||
|
||
const mockStateHandlers = require('../../utils/stateHandlers') | ||
|
||
describe('Challenge 3', () => { | ||
test(`It should return 6 | ||
[INPUT]: 12, 18`, () => { | ||
expect(MDC(12, 18)).toBe(6) | ||
}) | ||
test(`It should execute api call and set all states correctly`, async () => { | ||
await doRequest() | ||
expect(mockStateHandlers.setLoading).toBeCalledWith(true) | ||
expect(mockStateHandlers.setError).toBeCalledWith(false) | ||
|
||
test(`It should return 1 | ||
[INPUT]: 20, 33`, () => { | ||
expect(MDC(20, 33)).toBe(1) | ||
}) | ||
const response = await api() | ||
|
||
test(`It should return 23 | ||
[INPUT]: 368, 391`, () => { | ||
expect(MDC(368, 391)).toBe(23) | ||
}) | ||
expect(mockStateHandlers.setData).toBeCalledWith(response) | ||
|
||
test(`It should return 92 | ||
[INPUT]: 1380, 1472`, () => { | ||
expect(MDC(1380, 1472)).toBe(92) | ||
expect(mockStateHandlers.setLoading).lastCalledWith(false) | ||
expect(mockStateHandlers.setError).not.toBeCalledWith(true) | ||
}) | ||
}) |
Oops, something went wrong.