Skip to content
Merged
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
44 changes: 44 additions & 0 deletions docs/hackerrank/warmup/solveMeFirst.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# [Solve Me First](https://www.hackerrank.com/challenges/solve-me-first)

Difficulty: #easy
Category: #warmup

Complete the function solveMeFirst to compute the sum of two integers.

## Example

$ a = 7 $ \
$ b = 3 $

Return 10.

## Function Description

Complete the solveMeFirst function in the editor below.
solveMeFirst has the following parameters:

- int a: the first value
- int b: the second value

## Constraints

$ 1 \leq a, b \leq 1000 $

## Sample Input

```text
a = 2
b = 3
```

## Sample Output

```text
5
```

## Explanation

```text
2 + 3 = 5
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

#ifdef __cplusplus
extern "C" {
#endif

int HACKERRANK_WARMUP_solveMeFirst(int a, int b);

#ifdef __cplusplus
} // extern "C"
#endif
7 changes: 7 additions & 0 deletions src/lib/exercises/src/hackerrank/warmup/solve_me_first.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <exercises/hackerrank/warmup/solve_me_first.h>

/**
* @link Problem definition [[docs/hackerrank/warmup/solveMeFirst.md]]
*/

int HACKERRANK_WARMUP_solveMeFirst(int a, int b) { return a + b; }
27 changes: 27 additions & 0 deletions src/tests/unit/lib/hackerrank/warmup/solve_me_first.test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <catch2/catch_test_macros.hpp>

#include <exercises/hackerrank/warmup/solve_me_first.h>
#include <filesystem>
#include <fstream>
#include <nlohmann/json.hpp>
#include <vector>

using json = nlohmann::json;

TEST_CASE("solveMeFirst JSON Test Cases",
"[hackerrank] [jsontestcase] [warmup]") {
std::filesystem::path cwd = std::filesystem::current_path();
std::string path =
cwd.string() +
"/unit/lib/hackerrank/warmup/solve_me_first.testcases.json";

INFO("solveMeFirst JSON test cases FILE: " << path);

std::ifstream f(path);
json data = json::parse(f);

for (auto testcase : data) {
int result = HACKERRANK_WARMUP_solveMeFirst(testcase["a"], testcase["b"]);
CHECK(result == testcase["expected"]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{ "a": 0, "b": 0, "expected": 0 },
{ "a": 2, "b": 3, "expected": 5 },
{ "a": 0, "b": 7, "expected": 7 },
{ "a": 7, "b": 0, "expected": 7 },
{ "a": 7, "b": 7, "expected": 14 }
]