Skip to content

Instantly share code, notes, and snippets.

@junaidrahim
Created June 11, 2019 15:06
Show Gist options
  • Save junaidrahim/b3cb63552036048c3e45ec52aa7fd1ce to your computer and use it in GitHub Desktop.
Save junaidrahim/b3cb63552036048c3e45ec52aa7fd1ce to your computer and use it in GitHub Desktop.
test.cpp file for the medium post
#define CATCH_CONFIG_MAIN
#include "catch.hpp"
#include <vector>
#include "../include/binary_search.hpp"
std::vector<int> arr = {10,20,30,40,50,60,70,80,90,100};
TEST_CASE("Testing Binary Search") {
// testing for existing terms
REQUIRE(binary_search(arr, 10) == 0);
REQUIRE(binary_search(arr, 50) == 4);
REQUIRE(binary_search(arr, 100) == 9);
// testing for non existing terms
REQUIRE(binary_search(arr, -11) == -1);
REQUIRE(binary_search(arr, 176) == -1);
REQUIRE(binary_search(arr, 1230) == -1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment