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
# frozen_string_literal: true | |
class SafeHash < Hash | |
def initialize(namespace) | |
@namespace = namespace | |
@lock = Concurrent::ReadWriteLock.new | |
super | |
merge!({ @namespace => Concurrent::Map.new }) | |
end |
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
// check if integer is greater than zero or not | |
// this function returns true when a!=0 ie if (a<0 || a>0) | |
// this is not a good check for positive integers | |
// I realize this is not a good example - but for the sake of argument | |
bool check_if_positive(int a){ | |
if(a>0){ | |
return true; | |
} | |
else{ | |
return false; |
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
# A sample Makefile for building Google Test and using it in user | |
# tests. Please tweak it to suit your environment and project. You | |
# may want to move it to your project's root directory. | |
# | |
# SYNOPSIS: | |
# | |
# make [all] - makes everything. | |
# make TARGET - makes the given target. | |
# make clean - removes all files generated by make. |
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
#include "check_positive.h" | |
#include "gtest/gtest.h" | |
// Test to see if this function succeeds with positive integers | |
// TEST is a macro to define and name a test function - and they do not return values | |
// You can include and C++ code here along with GoogleTest assertions that you want to make | |
// --- Signature ---- // | |
// TEST(test_case_name,test_name){ | |
// test body | |
// } |
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
#ifndef CHECK_POSITIVE | |
#define CHECK_POSITIVE | |
bool check_if_positive(int a); | |
#endif | |
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
// check if integer is greater than zero or not | |
// this function returns true when a!=0 ie if (a<0 || a>0) | |
// this is not a good check for positive integers | |
// I realize this is not a good example - but for the sake of argument | |
bool check_if_positive(int a){ | |
return bool(a) | |
} |
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
#include "solution_code.h" | |
#include "gtest/gtest.h" | |
#include <climits> | |
// ---- Tests on Input ------ | |
// ---- Tests on 'solution_code' Function ----- | |
// checking validity of function on negative input | |
TEST(FunctionTest, SuccessNegative){ | |
float a[] = {-1.0,-5.0,-2.0,-3.0}; | |
float b[] = {-4.6,-2.1,-6.77,-4.01,-7.89,-254.24,-60.0}; |