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
;; Initialization | |
#NoEnv | |
SendMode Input | |
SetTitleMatchMode, 2 | |
;; MacBook-friendly modifier remapping | |
$RWin::RCtrl | |
$LWin::LAlt |
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
#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__); \ |
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 <assert.h> | |
#if TESTING | |
static int testing; | |
#endif | |
PRE_TEST | |
{ | |
printf("pre test\n"); | |
testing = 42; |
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 __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); |
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
// test.h - minimalistic unit testing | |
// | |
// AUTHOR: | |
// Per Vognsen | |
// | |
// LICENSE: | |
// Public domain | |
// | |
// EXAMPLE: | |
// |
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 <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; |
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 <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 |
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 <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); | |
} |
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
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; | |
} |
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
// 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--) { |