Skip to content

Instantly share code, notes, and snippets.

;; Initialization
#NoEnv
SendMode Input
SetTitleMatchMode, 2
;; MacBook-friendly modifier remapping
$RWin::RCtrl
$LWin::LAlt
@pervognsen
pervognsen / test.h
Created November 20, 2010 19:20
asdf
#define TEST_TOKENPASTE(x, y) x ## y
#define TEST_TOKENPASTE2(x, y) TEST_TOKENPASTE(x, y)
#define DO_TEST(name, phase) \
static void test_##name##(); \
struct TEST_TOKENPASTE2(test, __LINE__) \
{ \
TEST_TOKENPASTE2(test, __LINE__)() \
{ \
test_register(#name, test_##name, __FILE__, phase, __LINE__); \
@pervognsen
pervognsen / test.h
Created November 20, 2010 19:49
asdf
#include <assert.h>
#if TESTING
static int testing;
#endif
PRE_TEST
{
printf("pre test\n");
testing = 42;
@pervognsen
pervognsen / test.h
Created November 20, 2010 20:33
minimalistic unit testing
#ifndef __TEST_H__
#define __TEST_H__
#ifndef NO_TESTING
#define TESTING 1
// Plumbing
void test_main(int argc, char const **argv);
void test_register(const char *name, void (*run)(), const char *file, int phase, int line);
@pervognsen
pervognsen / test.h
Created November 20, 2010 22:00
minimalistic unit testing
// test.h - minimalistic unit testing
//
// AUTHOR:
// Per Vognsen
//
// LICENSE:
// Public domain
//
// EXAMPLE:
//
#include <string.h>
#include <assert.h>
#include <hash_map>
struct String_Hasher
{
static const size_t bucket_size = 4;
static const size_t min_buckets = 8;
#include <string.h>
#include <assert.h>
#include <hash_map>
// Here's how I'd structure the code to eliminate code duplication:
struct String_Hasher
{
size_t operator()(const char *value) const
#include <stdio.h>
#include <stdlib.h>
template<size_t N>
struct Chebyshev_CB
{
double operator()(double x)
{
return 2.0 * x * Chebyshev_CB<N-1>()(x) - Chebyshev_CB<N-2>()(x);
}
double chebyshev_per2(int n, double x)
{
double a = 1.0, b = x;
#define DO(i) case i: { const double t = b; b = 2.0 * x * b - a; a = t; }
switch (n) { DO(9) DO(8) DO(7) DO(6) DO(5) DO(4) DO(3) DO(2) DO(1) }
return a;
}
// chebyshev.cpp
#include <stdio.h>
#include <math.h>
static float chebyshev(int n, float x)
{
float a = 1.0f, b = x;
x += x;
while (n--) {