-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
55 additions
and
8 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
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
add_catch(test_neither_minimum_nor_maximum test.cpp) |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#pragma once | ||
|
||
#include <algorithm> | ||
#include <vector> | ||
|
||
class Solution { | ||
public: | ||
static int findNonMinOrMax(std::vector<int> nums) { | ||
if (nums.size() < 3) { | ||
return -1; | ||
} | ||
std::sort(nums.begin(), nums.begin() + 3); | ||
return nums[1]; | ||
} | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include <catch.hpp> | ||
|
||
#include <solution.hpp> | ||
|
||
TEST_CASE("Simple") { | ||
struct TestCase { | ||
std::vector<int> nums; | ||
int expected; | ||
}; | ||
|
||
std::vector<TestCase> test_cases{ | ||
{ | ||
.nums{3, 2, 1, 4}, | ||
.expected = 2, | ||
}, | ||
{ | ||
.nums{1, 2}, | ||
.expected = -1, | ||
}, | ||
{ | ||
.nums{2, 1, 3}, | ||
.expected = 2, | ||
}, | ||
}; | ||
|
||
for (const auto &[nums, expected] : test_cases) { | ||
const auto actual = Solution::findNonMinOrMax(nums); | ||
REQUIRE(expected == actual); | ||
} | ||
} |
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