Skip to content

Instantly share code, notes, and snippets.

View OPhamster's full-sized avatar
:octocat:
Working from home

Neel Maitra OPhamster

:octocat:
Working from home
  • clarisights
  • Bangalore
  • 06:30 (UTC +05:30)
View GitHub Profile
# frozen_string_literal: true
class SafeHash < Hash
def initialize(namespace)
@namespace = namespace
@lock = Concurrent::ReadWriteLock.new
super
merge!({ @namespace => Concurrent::Map.new })
end
@OPhamster
OPhamster / check_positive_corrected.cpp
Created July 30, 2017 14:45
New improved Function for positive integer check
// 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;
@OPhamster
OPhamster / Makefile
Created July 30, 2017 14:31
Makefile
# 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.
@OPhamster
OPhamster / check_positive_test.cpp
Last active July 30, 2017 14:05
Code to test check_positive.cpp
#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
// }
@OPhamster
OPhamster / check_positive.h
Last active July 30, 2017 13:25
Header for check_positive.cpp
#ifndef CHECK_POSITIVE
#define CHECK_POSITIVE
bool check_if_positive(int a);
#endif
@OPhamster
OPhamster / check_positive.cpp
Last active July 30, 2017 13:25
Definition to check for positive integer
// 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)
}
@OPhamster
OPhamster / code_test.cpp
Created July 24, 2017 01:01
googletest_sample_code
#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};