Skip to content

Instantly share code, notes, and snippets.

View lithiumhead's full-sized avatar

Anurag Chugh lithiumhead

View GitHub Profile
@lithiumhead
lithiumhead / 03bankacc_format.cpp
Created January 31, 2018 17:28
TEST_P() and code in same file - Test Fail & Formatted Output
#include <iostream>
#include <gtest/gtest.h>
struct BankAccount {
int balance = 0;
BankAccount() {
}
@lithiumhead
lithiumhead / 03bankacc_fail.cpp
Last active January 31, 2018 17:27
TEST_P() and code in same file - Test Fail
#include <iostream>
#include <gtest/gtest.h>
struct BankAccount {
int balance = 0;
BankAccount() {
}
explicit BankAccount(const int balance)
: balance{balance} {
@lithiumhead
lithiumhead / 02bankacc_pass.cpp
Last active January 31, 2018 17:24
TEST_F() and code in same file - Test Pass
#include <iostream>
#include <gtest/gtest.h>
struct BankAccount {
int balance = 0;
BankAccount() {
}
explicit BankAccount(const int balance)
@lithiumhead
lithiumhead / 01sqrt_pass.cpp
Created January 31, 2018 17:13
TEST() and code in same file - Test Pass
#include <iostream>
#include <math.h>
#include <gtest/gtest.h>
double squareroot (double a) {
if(a<0)
return -1;
else
return sqrt(a);
};
@lithiumhead
lithiumhead / 01sqrt_fail.cpp
Last active January 31, 2018 17:13
TEST() and code in same file - Test Fail
#include <iostream>
#include <gtest/gtest.h>
double squareroot (double) {
return 0;
};
TEST (SquareRootTest, PositiveNos) {
EXPECT_EQ (18.0, squareroot (324.0));
EXPECT_EQ (25.4, squareroot (645.16));
@lithiumhead
lithiumhead / BUILD
Last active September 4, 2017 06:32
Hello World - C Shared Library
package(default_visibility = ["//visibility:public"])
cc_library(
name = "hello",
srcs = ["libhello.c"],
hdrs = ["libhello.h"],
)
cc_binary(
name = "main.exe",
@lithiumhead
lithiumhead / Makefile
Created August 26, 2017 08:58
Hello World - C Shared Library
############ Configure the following four variable and set your sources and names
LIB_TARGET_NAME = hello
LIB_SRCS = libhello.c
EXE_TARGET_NAME = main.exe
EXE_SRCS = main.c
############ The following variables are auto generated
CC = gcc
RM = rm -f
CURR_DIRR = $(shell pwd)
@lithiumhead
lithiumhead / main.c
Created August 26, 2017 08:39
Hello World - C Shared Library
#include <stdio.h>
#include "libhello.h"
int main(void)
{
puts("This is a shared library test...");
hello();
return 0;
}
@lithiumhead
lithiumhead / libhello.h
Created August 26, 2017 08:38
Hello World - C Shared Library
#ifndef libhello_h__
#define libhello_h__
extern void hello(void);
#endif // libhello_h__
@lithiumhead
lithiumhead / libhello.c
Created August 26, 2017 08:37
Hello World - C Shared Library
#include <stdio.h>
void hello(void)
{
puts("Hello, I'm a shared library");
}