mirror of
https://github.com/theoludwig/programming-challenges.git
synced 2024-12-08 00:45:29 +01:00
feat(cli): add --all
option to run test
command
This commit is contained in:
parent
aeff95e691
commit
0a27b9e1a1
@ -45,7 +45,7 @@ Gitpod will automatically setup an environment for you.
|
|||||||
#### Prerequisites
|
#### Prerequisites
|
||||||
|
|
||||||
- [Node.js](https://nodejs.org/) >= 16.0.0
|
- [Node.js](https://nodejs.org/) >= 16.0.0
|
||||||
- [npm](https://npmjs.com/) >= 7.0.0
|
- [npm](https://npmjs.com/) >= 8.0.0
|
||||||
- [Docker](https://www.docker.com/)
|
- [Docker](https://www.docker.com/)
|
||||||
|
|
||||||
#### Installation
|
#### Installation
|
||||||
|
@ -9,7 +9,7 @@ void character_append(char* string, char character) {
|
|||||||
string[length + 1] = '\0';
|
string[length + 1] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
const char character_to_upper(const char character) {
|
char character_to_upper(char character) {
|
||||||
char ascii_a = 'a';
|
char ascii_a = 'a';
|
||||||
char ascii_A = 'A';
|
char ascii_A = 'A';
|
||||||
char ascii_z = 'z';
|
char ascii_z = 'z';
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#ifndef CHARACTER_H
|
#ifndef __CHARACTER__
|
||||||
#define CHARACTER_H
|
#define __CHARACTER__
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Append a character to a string, assuming string points to an array
|
* @brief Append a character to a string, assuming string points to an array
|
||||||
@ -14,8 +14,8 @@ void character_append(char* string, char character);
|
|||||||
* @brief Converts the character to uppercase.
|
* @brief Converts the character to uppercase.
|
||||||
*
|
*
|
||||||
* @param character
|
* @param character
|
||||||
* @return const char
|
* @return char
|
||||||
*/
|
*/
|
||||||
const char character_to_upper(const char character);
|
char character_to_upper(char character);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#ifndef INPUT_H
|
#ifndef __INPUT__
|
||||||
#define INPUT_H
|
#define __INPUT__
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Read a line from stdin.
|
* @brief Read a line from stdin.
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#ifndef STRING_H
|
#ifndef __STRING__
|
||||||
#define STRING_H
|
#define __STRING__
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Converts all the alphabetic characters in a string to uppercase.
|
* @brief Converts all the alphabetic characters in a string to uppercase.
|
||||||
|
@ -29,7 +29,7 @@ char* string_caesar_cipher(char* string, int shift) {
|
|||||||
for (size_t index = 0; index < string_length; index++) {
|
for (size_t index = 0; index < string_length; index++) {
|
||||||
char letter = string[index];
|
char letter = string[index];
|
||||||
if (letter != ' ') {
|
if (letter != ' ') {
|
||||||
for (char index_alphabet = 0; index_alphabet < ALPHABET_LENGTH; index_alphabet++) {
|
for (int index_alphabet = 0; index_alphabet < ALPHABET_LENGTH; index_alphabet++) {
|
||||||
char current_letter = 'A' + index_alphabet;
|
char current_letter = 'A' + index_alphabet;
|
||||||
if (string[index] == current_letter) {
|
if (string[index] == current_letter) {
|
||||||
letter = shifted_alphabet[index_alphabet];
|
letter = shifted_alphabet[index_alphabet];
|
||||||
|
@ -9,7 +9,7 @@ void character_append(char* string, char character) {
|
|||||||
string[length + 1] = '\0';
|
string[length + 1] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
const char character_to_upper(const char character) {
|
char character_to_upper(char character) {
|
||||||
char ascii_a = 'a';
|
char ascii_a = 'a';
|
||||||
char ascii_A = 'A';
|
char ascii_A = 'A';
|
||||||
char ascii_z = 'z';
|
char ascii_z = 'z';
|
||||||
|
@ -14,8 +14,8 @@ void character_append(char* string, char character);
|
|||||||
* @brief Converts the character to uppercase.
|
* @brief Converts the character to uppercase.
|
||||||
*
|
*
|
||||||
* @param character
|
* @param character
|
||||||
* @return const char
|
* @return char
|
||||||
*/
|
*/
|
||||||
const char character_to_upper(const char character);
|
char character_to_upper(char character);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -42,8 +42,8 @@ int main() {
|
|||||||
if (is_last_number) {
|
if (is_last_number) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (numbers[index] + couple_index == numbers[index + couple_index]) {
|
if ((int)(numbers[index] + couple_index) == numbers[index + couple_index]) {
|
||||||
consecutive[consecutive_length] = numbers[index] + couple_index;
|
consecutive[consecutive_length] = (int)(numbers[index] + couple_index);
|
||||||
consecutive_length++;
|
consecutive_length++;
|
||||||
}
|
}
|
||||||
bool is_consecutive = consecutive_length == couple_length;
|
bool is_consecutive = consecutive_length == couple_length;
|
||||||
|
10
challenges/hello-world/solutions/c/function/character.c
Normal file
10
challenges/hello-world/solutions/c/function/character.c
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#include "character.h"
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
void character_append(char* string, char character) {
|
||||||
|
size_t length = strlen(string);
|
||||||
|
string[length] = character;
|
||||||
|
string[length + 1] = '\0';
|
||||||
|
}
|
13
challenges/hello-world/solutions/c/function/character.h
Normal file
13
challenges/hello-world/solutions/c/function/character.h
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#ifndef __CHARACTER__
|
||||||
|
#define __CHARACTER__
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Append a character to a string, assuming string points to an array
|
||||||
|
* with enough space.
|
||||||
|
*
|
||||||
|
* @param string
|
||||||
|
* @param character
|
||||||
|
*/
|
||||||
|
void character_append(char* string, char character);
|
||||||
|
|
||||||
|
#endif
|
19
challenges/hello-world/solutions/c/function/input.c
Normal file
19
challenges/hello-world/solutions/c/function/input.c
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#include "input.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "character.h"
|
||||||
|
|
||||||
|
char* input() {
|
||||||
|
char character;
|
||||||
|
size_t length = 1;
|
||||||
|
char* string = malloc(length * sizeof(char));
|
||||||
|
*string = '\0';
|
||||||
|
while ((character = getchar()) != '\n' && character != EOF) {
|
||||||
|
length++;
|
||||||
|
string = realloc(string, length * sizeof(char));
|
||||||
|
character_append(string, character);
|
||||||
|
}
|
||||||
|
return string;
|
||||||
|
}
|
11
challenges/hello-world/solutions/c/function/input.h
Normal file
11
challenges/hello-world/solutions/c/function/input.h
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#ifndef __INPUT__
|
||||||
|
#define __INPUT__
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Read a line from stdin.
|
||||||
|
*
|
||||||
|
* @return char*
|
||||||
|
*/
|
||||||
|
char* input();
|
||||||
|
|
||||||
|
#endif
|
@ -1,10 +1,10 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "input.h"
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
char input[1024];
|
char *string = input();
|
||||||
while (scanf("%s", &input) != EOF) {
|
printf("Hello, %s!\n", string);
|
||||||
printf("Hello, %s!", input);
|
|
||||||
}
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ void character_append(char* string, char character) {
|
|||||||
string[length + 1] = '\0';
|
string[length + 1] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
const char character_to_upper(const char character) {
|
char character_to_upper(char character) {
|
||||||
char ascii_a = 'a';
|
char ascii_a = 'a';
|
||||||
char ascii_A = 'A';
|
char ascii_A = 'A';
|
||||||
char ascii_z = 'z';
|
char ascii_z = 'z';
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#ifndef CHARACTER_H
|
#ifndef __CHARACTER__
|
||||||
#define CHARACTER_H
|
#define __CHARACTER__
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Append a character to a string, assuming string points to an array
|
* @brief Append a character to a string, assuming string points to an array
|
||||||
@ -14,8 +14,8 @@ void character_append(char* string, char character);
|
|||||||
* @brief Converts the character to uppercase.
|
* @brief Converts the character to uppercase.
|
||||||
*
|
*
|
||||||
* @param character
|
* @param character
|
||||||
* @return const char
|
* @return char
|
||||||
*/
|
*/
|
||||||
const char character_to_upper(const char character);
|
char character_to_upper(char character);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include "input.h"
|
#include "input.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "character.h"
|
#include "character.h"
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#ifndef INPUT_H
|
#ifndef __INPUT__
|
||||||
#define INPUT_H
|
#define __INPUT__
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Read a line from stdin.
|
* @brief Read a line from stdin.
|
||||||
|
@ -18,7 +18,7 @@ char* string_to_upper(const char* string) {
|
|||||||
char* string_reverse(const char* string) {
|
char* string_reverse(const char* string) {
|
||||||
size_t string_length = strlen(string);
|
size_t string_length = strlen(string);
|
||||||
char* result = malloc(sizeof(char) * (string_length + 1));
|
char* result = malloc(sizeof(char) * (string_length + 1));
|
||||||
for (size_t index = string_length - 1; index != -1; index--) {
|
for (int index = string_length - 1; index != -1; index--) {
|
||||||
character_append(result, string[index]);
|
character_append(result, string[index]);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#ifndef STRING_H
|
#ifndef __STRING__
|
||||||
#define STRING_H
|
#define __STRING__
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ void character_append(char* string, char character) {
|
|||||||
string[length + 1] = '\0';
|
string[length + 1] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
void character_print(char* character, int number_of_times) {
|
void character_print(char* character, size_t number_of_times) {
|
||||||
for (size_t iteration = 0; iteration < number_of_times; iteration++) {
|
for (size_t iteration = 0; iteration < number_of_times; iteration++) {
|
||||||
printf("%s", character);
|
printf("%s", character);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
#ifndef CHARACTER_H
|
#ifndef __CHARACTER__
|
||||||
#define CHARACTER_H
|
#define __CHARACTER__
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Append a character to a string, assuming string points to an array
|
* @brief Append a character to a string, assuming string points to an array
|
||||||
@ -10,6 +12,6 @@
|
|||||||
*/
|
*/
|
||||||
void character_append(char* string, char character);
|
void character_append(char* string, char character);
|
||||||
|
|
||||||
void character_print(char* character, int number_of_times);
|
void character_print(char* character, size_t number_of_times);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#ifndef INPUT_H
|
#ifndef __INPUT__
|
||||||
#define INPUT_H
|
#define __INPUT__
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Read a line from stdin.
|
* @brief Read a line from stdin.
|
||||||
|
@ -12,10 +12,10 @@ int main() {
|
|||||||
|
|
||||||
int step = strcmp(type, "normal") == 0 ? 1 : height;
|
int step = strcmp(type, "normal") == 0 ? 1 : height;
|
||||||
while ((strcmp(type, "normal") == 0 && step <= height) || (strcmp(type, "reverse") == 0 && step != 0)) {
|
while ((strcmp(type, "normal") == 0 && step <= height) || (strcmp(type, "reverse") == 0 && step != 0)) {
|
||||||
int numberOfStars = (step * 2) - 1;
|
size_t numberOfStars = (step * 2) - 1;
|
||||||
int totalNumberOfLocations = (height * 2) - 1;
|
size_t totalNumberOfLocations = (height * 2) - 1;
|
||||||
int totalNumberOfSpaces = totalNumberOfLocations - numberOfStars;
|
size_t totalNumberOfSpaces = totalNumberOfLocations - numberOfStars;
|
||||||
int numberOfSpacesOnEachSide = totalNumberOfSpaces / 2;
|
size_t numberOfSpacesOnEachSide = totalNumberOfSpaces / 2;
|
||||||
character_print(" ", numberOfSpacesOnEachSide);
|
character_print(" ", numberOfSpacesOnEachSide);
|
||||||
character_print("*", numberOfStars);
|
character_print("*", numberOfStars);
|
||||||
character_print(" ", numberOfSpacesOnEachSide);
|
character_print(" ", numberOfSpacesOnEachSide);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#ifndef BUBBLE_SORT_H
|
#ifndef __BUBBLE_SORT__
|
||||||
#define BUBBLE_SORT_H
|
#define __BUBBLE_SORT__
|
||||||
|
|
||||||
void swap_numbers(int *value_1, int *value_2);
|
void swap_numbers(int *value_1, int *value_2);
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
int current_number;
|
int current_number;
|
||||||
int length = scanf("%d", ¤t_number);
|
scanf("%d", ¤t_number);
|
||||||
int *numbers = malloc(current_number * sizeof(int));
|
int *numbers = malloc(current_number * sizeof(int));
|
||||||
int index_input = 0;
|
int index_input = 0;
|
||||||
while (scanf("%d", ¤t_number) != EOF) {
|
while (scanf("%d", ¤t_number) != EOF) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#ifndef INSERTION_SORT_H
|
#ifndef __INSERTION_SORT__
|
||||||
#define INSERTION_SORT_H
|
#define __INSERTION_SORT__
|
||||||
|
|
||||||
void insertion_sort(int *numbers, const int length);
|
void insertion_sort(int *numbers, const int length);
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
int current_number;
|
int current_number;
|
||||||
int length = scanf("%d", ¤t_number);
|
scanf("%d", ¤t_number);
|
||||||
int *numbers = malloc(current_number * sizeof(int));
|
int *numbers = malloc(current_number * sizeof(int));
|
||||||
int index_input = 0;
|
int index_input = 0;
|
||||||
while (scanf("%d", ¤t_number) != EOF) {
|
while (scanf("%d", ¤t_number) != EOF) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#ifndef MERGE_SORT_H
|
#ifndef __MERGE_SORT__
|
||||||
#define MERGE_SORT_H
|
#define __MERGE_SORT__
|
||||||
|
|
||||||
void merge(int numbers[], int left_index, int middle_index, int right_index);
|
void merge(int numbers[], int left_index, int middle_index, int right_index);
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
int current_number;
|
int current_number;
|
||||||
int length = scanf("%d", ¤t_number);
|
scanf("%d", ¤t_number);
|
||||||
int *numbers = malloc(current_number * sizeof(int));
|
int *numbers = malloc(current_number * sizeof(int));
|
||||||
int index_input = 0;
|
int index_input = 0;
|
||||||
while (scanf("%d", ¤t_number) != EOF) {
|
while (scanf("%d", ¤t_number) != EOF) {
|
||||||
|
@ -5,15 +5,12 @@ char* triangle_type(int triangle_sides[3]) {
|
|||||||
if ((triangle_sides[0] + triangle_sides[1] < triangle_sides[2]) || (triangle_sides[2] + triangle_sides[0] < triangle_sides[1]) || (triangle_sides[2] + triangle_sides[1] < triangle_sides[0])) {
|
if ((triangle_sides[0] + triangle_sides[1] < triangle_sides[2]) || (triangle_sides[2] + triangle_sides[0] < triangle_sides[1]) || (triangle_sides[2] + triangle_sides[1] < triangle_sides[0])) {
|
||||||
return "impossible";
|
return "impossible";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (triangle_sides[0] == triangle_sides[1] && triangle_sides[1] == triangle_sides[2]) {
|
if (triangle_sides[0] == triangle_sides[1] && triangle_sides[1] == triangle_sides[2]) {
|
||||||
return "equilateral";
|
return "equilateral";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (triangle_sides[0] == triangle_sides[1] || triangle_sides[1] == triangle_sides[2] || triangle_sides[2] == triangle_sides[0]) {
|
if (triangle_sides[0] == triangle_sides[1] || triangle_sides[1] == triangle_sides[2] || triangle_sides[2] == triangle_sides[0]) {
|
||||||
return "isosceles";
|
return "isosceles";
|
||||||
}
|
}
|
||||||
|
|
||||||
return "scalene";
|
return "scalene";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,9 +1,13 @@
|
|||||||
|
import fs from 'node:fs'
|
||||||
|
import path from 'node:path'
|
||||||
|
|
||||||
import { Command, Option } from 'clipanion'
|
import { Command, Option } from 'clipanion'
|
||||||
import * as typanion from 'typanion'
|
import * as typanion from 'typanion'
|
||||||
import chalk from 'chalk'
|
import chalk from 'chalk'
|
||||||
|
|
||||||
import { Solution } from '../../services/Solution'
|
import { Solution } from '../../services/Solution'
|
||||||
import { GitAffected } from '../../services/GitAffected'
|
import { GitAffected } from '../../services/GitAffected'
|
||||||
|
import { template } from '../../services/Template'
|
||||||
|
|
||||||
const successMessage = `${chalk.bold.green('Success:')} Tests passed! 🎉`
|
const successMessage = `${chalk.bold.green('Success:')} Tests passed! 🎉`
|
||||||
|
|
||||||
@ -16,7 +20,7 @@ export class RunTestCommand extends Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public programmingLanguage = Option.String('--language', {
|
public programmingLanguage = Option.String('--language', {
|
||||||
description: 'The programming language to use to solve the challenge.',
|
description: 'The programming language used to solve the challenge.',
|
||||||
validator: typanion.isString()
|
validator: typanion.isString()
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -34,6 +38,10 @@ export class RunTestCommand extends Command {
|
|||||||
description: 'Only run the tests for the affected files in `git`.'
|
description: 'Only run the tests for the affected files in `git`.'
|
||||||
})
|
})
|
||||||
|
|
||||||
|
public all = Option.Boolean('--all', false, {
|
||||||
|
description: 'Run the tests for all the solutions.'
|
||||||
|
})
|
||||||
|
|
||||||
public isContinuousIntegration = Option.Boolean('--ci', false, {
|
public isContinuousIntegration = Option.Boolean('--ci', false, {
|
||||||
description: 'Run the tests for the Continuous Integration (CI).'
|
description: 'Run the tests for the Continuous Integration (CI).'
|
||||||
})
|
})
|
||||||
@ -42,21 +50,59 @@ export class RunTestCommand extends Command {
|
|||||||
description: 'Base of the current branch (usually master)'
|
description: 'Base of the current branch (usually master)'
|
||||||
})
|
})
|
||||||
|
|
||||||
|
async runTests (solutions: Solution[]): Promise<number> {
|
||||||
|
for (const solution of solutions) {
|
||||||
|
await solution.test()
|
||||||
|
console.log('\n------------------------------\n')
|
||||||
|
}
|
||||||
|
console.log(successMessage)
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
async execute (): Promise<number> {
|
async execute (): Promise<number> {
|
||||||
console.log()
|
console.log()
|
||||||
try {
|
try {
|
||||||
|
if (this.programmingLanguage != null) {
|
||||||
|
await template.verifySupportedProgrammingLanguage(this.programmingLanguage)
|
||||||
|
}
|
||||||
|
if (this.all) {
|
||||||
|
const challengesPath = path.join(
|
||||||
|
__dirname,
|
||||||
|
'..',
|
||||||
|
'..',
|
||||||
|
'..',
|
||||||
|
'challenges'
|
||||||
|
)
|
||||||
|
const challenges = await fs.promises.readdir(challengesPath)
|
||||||
|
const paths: string[] = []
|
||||||
|
for (const challenge of challenges) {
|
||||||
|
const solutionsPath = path.join(challengesPath, challenge, 'solutions')
|
||||||
|
const languagesSolution = (await fs.promises.readdir(solutionsPath)).filter(
|
||||||
|
(name) => {
|
||||||
|
if (this.programmingLanguage != null) {
|
||||||
|
return name === this.programmingLanguage
|
||||||
|
}
|
||||||
|
return name !== '.gitkeep'
|
||||||
|
}
|
||||||
|
)
|
||||||
|
for (const language of languagesSolution) {
|
||||||
|
const solutionPath = (await fs.promises.readdir(path.join(solutionsPath, language))).map((solutionName) => {
|
||||||
|
return `challenges/${challenge}/solutions/${language}/${solutionName}`
|
||||||
|
})
|
||||||
|
paths.push(...solutionPath)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const solutions = await Solution.getManyByPaths(paths)
|
||||||
|
await this.runTests(solutions)
|
||||||
|
return 0
|
||||||
|
}
|
||||||
if (this.affected) {
|
if (this.affected) {
|
||||||
const gitAffected = new GitAffected({
|
const gitAffected = new GitAffected({
|
||||||
isContinuousIntegration: this.isContinuousIntegration,
|
isContinuousIntegration: this.isContinuousIntegration,
|
||||||
base: this.base
|
base: this.base
|
||||||
})
|
})
|
||||||
const solutions = await gitAffected.getAffectedSolutions()
|
const solutions = await gitAffected.getAffectedSolutions()
|
||||||
for (const solution of solutions) {
|
return await this.runTests(solutions)
|
||||||
await solution.test()
|
|
||||||
console.log('\n------------------------------\n')
|
|
||||||
}
|
|
||||||
console.log(successMessage)
|
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
this.solutionName == null ||
|
this.solutionName == null ||
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
import execa from 'execa'
|
import execa from 'execa'
|
||||||
|
|
||||||
import { Challenge } from './Challenge'
|
|
||||||
import { Solution } from './Solution'
|
import { Solution } from './Solution'
|
||||||
import { isExistingPath } from '../utils/isExistingPath'
|
|
||||||
|
|
||||||
const solutionsRegex = new RegExp(
|
const solutionsRegex = new RegExp(
|
||||||
/challenges\/[\s\S]*\/solutions\/(c|cpp|cs|dart|java|javascript|python|rust|typescript)\/[\s\S]*\/(solution|Solution).(c|cpp|cs|dart|java|js|py|rs|ts)/
|
/challenges\/[\s\S]*\/solutions\/(c|cpp|cs|dart|java|javascript|python|rust|typescript)\/[\s\S]*\/(solution|Solution).(c|cpp|cs|dart|java|js|py|rs|ts)/
|
||||||
@ -72,22 +70,6 @@ export class GitAffected implements GitAffectedOptions {
|
|||||||
const affectedSolutionsPaths = files.filter((filePath) => {
|
const affectedSolutionsPaths = files.filter((filePath) => {
|
||||||
return solutionsRegex.test(filePath)
|
return solutionsRegex.test(filePath)
|
||||||
})
|
})
|
||||||
const solutions: string[] = []
|
return await Solution.getManyByPaths(affectedSolutionsPaths)
|
||||||
for (const path of affectedSolutionsPaths) {
|
|
||||||
if (await isExistingPath(path)) {
|
|
||||||
solutions.push(path)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return solutions.map((solution) => {
|
|
||||||
const [, challengeName, , programmingLanguageName, solutionName] =
|
|
||||||
solution.split('/')
|
|
||||||
return new Solution({
|
|
||||||
challenge: new Challenge({
|
|
||||||
name: challengeName
|
|
||||||
}),
|
|
||||||
name: solutionName,
|
|
||||||
programmingLanguageName
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -101,4 +101,29 @@ export class Solution implements SolutionOptions {
|
|||||||
}
|
}
|
||||||
return solution
|
return solution
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Solutions by relative paths.
|
||||||
|
* @param paths relative to `challenges` (e.g: `challenges/hello-world/solutions/c/function`)
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
static async getManyByPaths (paths: string[]): Promise<Solution[]> {
|
||||||
|
const solutions: string[] = []
|
||||||
|
for (const path of paths) {
|
||||||
|
if (await isExistingPath(path)) {
|
||||||
|
solutions.push(path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return solutions.map((solution) => {
|
||||||
|
const [, challengeName, , programmingLanguageName, solutionName] =
|
||||||
|
solution.split('/')
|
||||||
|
return new Solution({
|
||||||
|
challenge: new Challenge({
|
||||||
|
name: challengeName
|
||||||
|
}),
|
||||||
|
name: solutionName,
|
||||||
|
programmingLanguageName
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -73,9 +73,7 @@ class Template {
|
|||||||
public async solution (options: TemplateSolutionOptions): Promise<void> {
|
public async solution (options: TemplateSolutionOptions): Promise<void> {
|
||||||
const { destination, githubUser, name, challengeName, programmingLanguageName } = options
|
const { destination, githubUser, name, challengeName, programmingLanguageName } = options
|
||||||
const templateLanguagePath = path.join(TEMPLATE_SOLUTION_PATH, programmingLanguageName)
|
const templateLanguagePath = path.join(TEMPLATE_SOLUTION_PATH, programmingLanguageName)
|
||||||
if (!(await isExistingPath(templateLanguagePath))) {
|
await this.verifySupportedProgrammingLanguage(programmingLanguageName)
|
||||||
throw new Error('This programming language is not supported yet.')
|
|
||||||
}
|
|
||||||
await fs.promises.mkdir(destination, { recursive: true })
|
await fs.promises.mkdir(destination, { recursive: true })
|
||||||
await copyDirectory(templateLanguagePath, destination)
|
await copyDirectory(templateLanguagePath, destination)
|
||||||
await copyDirectory(TEMPLATE_SOLUTION_BASE_PATH, destination)
|
await copyDirectory(TEMPLATE_SOLUTION_BASE_PATH, destination)
|
||||||
@ -95,6 +93,13 @@ class Template {
|
|||||||
destination
|
destination
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async verifySupportedProgrammingLanguage (language: string): Promise<void> {
|
||||||
|
const templateLanguagePath = path.join(TEMPLATE_SOLUTION_PATH, language)
|
||||||
|
if (!(await isExistingPath(templateLanguagePath))) {
|
||||||
|
throw new Error('This programming language is not supported yet.')
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const template = new Template()
|
export const template = new Template()
|
||||||
|
3066
package-lock.json
generated
3066
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
20
package.json
20
package.json
@ -9,7 +9,7 @@
|
|||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=16.0.0",
|
"node": ">=16.0.0",
|
||||||
"npm": ">=7.0.0"
|
"npm": ">=8.0.0"
|
||||||
},
|
},
|
||||||
"ts-standard": {
|
"ts-standard": {
|
||||||
"ignore": [
|
"ignore": [
|
||||||
@ -38,29 +38,29 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"chalk": "4.1.2",
|
"chalk": "4.1.2",
|
||||||
"clipanion": "3.0.1",
|
"clipanion": "3.0.1",
|
||||||
"date-and-time": "2.0.0",
|
"date-and-time": "2.0.1",
|
||||||
"execa": "5.1.1",
|
"execa": "5.1.1",
|
||||||
"ora": "5.4.1",
|
"ora": "5.4.1",
|
||||||
"replace-in-file": "6.2.0",
|
"replace-in-file": "6.2.0",
|
||||||
"table": "6.7.1",
|
"table": "6.7.2",
|
||||||
"typanion": "3.5.0",
|
"typanion": "3.5.0",
|
||||||
"validate-npm-package-name": "3.0.0"
|
"validate-npm-package-name": "3.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@commitlint/cli": "13.1.0",
|
"@commitlint/cli": "13.2.1",
|
||||||
"@commitlint/config-conventional": "13.1.0",
|
"@commitlint/config-conventional": "13.2.0",
|
||||||
"@types/date-and-time": "0.13.0",
|
"@types/date-and-time": "0.13.0",
|
||||||
"@types/jest": "27.0.2",
|
"@types/jest": "27.0.2",
|
||||||
"@types/mock-fs": "4.13.1",
|
"@types/mock-fs": "4.13.1",
|
||||||
"@types/node": "16.9.4",
|
"@types/node": "16.10.8",
|
||||||
"@types/validate-npm-package-name": "3.0.3",
|
"@types/validate-npm-package-name": "3.0.3",
|
||||||
"editorconfig-checker": "4.0.2",
|
"editorconfig-checker": "4.0.2",
|
||||||
"jest": "27.2.1",
|
"jest": "27.2.5",
|
||||||
"markdownlint-cli": "0.28.1",
|
"markdownlint-cli": "0.29.0",
|
||||||
"mock-fs": "5.1.0",
|
"mock-fs": "5.1.1",
|
||||||
"rimraf": "3.0.2",
|
"rimraf": "3.0.2",
|
||||||
"ts-jest": "27.0.5",
|
"ts-jest": "27.0.5",
|
||||||
"ts-standard": "10.0.0",
|
"ts-standard": "10.0.0",
|
||||||
"typescript": "4.4.3"
|
"typescript": "4.4.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
FROM gcc:11.2.0
|
FROM gcc:11.2.0
|
||||||
COPY ./ ./
|
COPY ./ ./
|
||||||
RUN gcc *.c --output=solution
|
RUN gcc -Wall -Wextra -Werror *.c --output=solution
|
||||||
CMD ["./solution"]
|
CMD ["./solution"]
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
FROM dart:2.14.2
|
FROM dart:2.14.3
|
||||||
COPY ./ ./
|
COPY ./ ./
|
||||||
CMD ["dart", "run", "solution.dart"]
|
CMD ["dart", "run", "solution.dart"]
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
FROM node:16.9.1
|
FROM node:16.11.1
|
||||||
COPY ./ ./
|
COPY ./ ./
|
||||||
CMD ["node", "solution.js"]
|
CMD ["node", "solution.js"]
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
FROM python:3.9.7
|
FROM python:3.10.0
|
||||||
COPY ./ ./
|
COPY ./ ./
|
||||||
CMD ["python", "solution.py"]
|
CMD ["python", "solution.py"]
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
FROM node:16.9.1
|
FROM node:16.11.1
|
||||||
RUN npm install --global ts-node typescript @types/node
|
RUN npm install --global ts-node typescript @types/node
|
||||||
COPY ./ ./
|
COPY ./ ./
|
||||||
CMD ["ts-node", "solution.ts"]
|
CMD ["ts-node", "solution.ts"]
|
||||||
|
10
templates/solution/c/character.c
Normal file
10
templates/solution/c/character.c
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#include "character.h"
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
void character_append(char* string, char character) {
|
||||||
|
size_t length = strlen(string);
|
||||||
|
string[length] = character;
|
||||||
|
string[length + 1] = '\0';
|
||||||
|
}
|
13
templates/solution/c/character.h
Normal file
13
templates/solution/c/character.h
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#ifndef __CHARACTER__
|
||||||
|
#define __CHARACTER__
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Append a character to a string, assuming string points to an array
|
||||||
|
* with enough space.
|
||||||
|
*
|
||||||
|
* @param string
|
||||||
|
* @param character
|
||||||
|
*/
|
||||||
|
void character_append(char* string, char character);
|
||||||
|
|
||||||
|
#endif
|
19
templates/solution/c/input.c
Normal file
19
templates/solution/c/input.c
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#include "input.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "character.h"
|
||||||
|
|
||||||
|
char* input() {
|
||||||
|
char character;
|
||||||
|
size_t length = 1;
|
||||||
|
char* string = malloc(length * sizeof(char));
|
||||||
|
*string = '\0';
|
||||||
|
while ((character = getchar()) != '\n' && character != EOF) {
|
||||||
|
length++;
|
||||||
|
string = realloc(string, length * sizeof(char));
|
||||||
|
character_append(string, character);
|
||||||
|
}
|
||||||
|
return string;
|
||||||
|
}
|
11
templates/solution/c/input.h
Normal file
11
templates/solution/c/input.h
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#ifndef __INPUT__
|
||||||
|
#define __INPUT__
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Read a line from stdin.
|
||||||
|
*
|
||||||
|
* @return char*
|
||||||
|
*/
|
||||||
|
char* input();
|
||||||
|
|
||||||
|
#endif
|
@ -1,10 +1,10 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "input.h"
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
char input[1024];
|
char *string = input();
|
||||||
while (scanf("%s", &input) != EOF) {
|
printf("Hello, %s!\n", string);
|
||||||
printf("Hello, %s!", input);
|
|
||||||
}
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user