Skip to content

Instantly share code, notes, and snippets.

View josephjunker's full-sized avatar

Joseph Junker josephjunker

View GitHub Profile
@josephjunker
josephjunker / notes.md
Last active October 24, 2020 00:26
A brief overview of property-based testing

What is property-based testing

When people talk about automated testing, 98% of the time they're thinking of "example-based testing". This is a testing methodology that goes something like this:

  • Think of the way a component should behave
  • Specify a set of inputs to the component
  • Specify the expected output of the component, given these inputs
  • Repeat these steps for every major "category" of inputs. (i.e. if an input is a number, you'd probably use a large number, a negative number, a small number, 1, and 0, and consider these covering all of your cases.)

Each input/output pair forms an example of the way the program should behave. A test suite written using this style forms an argument like this: "All inputs in the same category should act the same. I've specified examples of every category, and the categories I've specified cover all possible categories, so therefore my system is correct." I won't try to get into the upsides and downsides of this here.

@josephjunker
josephjunker / Eleksmaker.py
Created April 24, 2020 20:31
elekmaker inkscape plugin, fed through 2to3 with a couple tweaks
"""
Modified by Jay Johnson 2015, J Tech Photonics, Inc., jtechphotonics.com
modified by Adam Polak 2014, polakiumengineering.org
based on Copyright (C) 2009 Nick Drobchenko, [email protected]
based on gcode.py (C) 2007 hugomatic...
based on addnodes.py (C) 2005,2007 Aaron Spike, [email protected]
based on dots.py (C) 2005 Aaron Spike, [email protected]
based on interp.py (C) 2005 Aaron Spike, [email protected]
based on bezmisc.py (C) 2005 Aaron Spike, [email protected]
@josephjunker
josephjunker / Thunk.dfy
Created January 18, 2020 18:51
dafny packrat prototype
datatype Option<T> = Some(t: T) | None
class Thunk <T> {
var fn : () -> T, cache : Option<T>;
constructor (fn: () -> T)
{
this.fn := fn;
this.cache := None;
}
@josephjunker
josephjunker / deferred-non-HKT.js
Last active February 27, 2018 22:38
Laziness primitive for JS, flow-static-land compatible
// Note that this file still needs testing
// @flow
export opaque type Deferred<A> = Thunk<A> | Pure<A>;
class Suspended<A> {
fn: () => A;
constructor(fn: () => A) {
this.fn = fn;
@josephjunker
josephjunker / boolean-expression-ast.js
Created July 29, 2017 02:53
BooleanExpr recursion scheme example
// @flow
import type { Functor } from "flow-static-land/lib/Functor";
import type { HKT } from "flow-static-land/lib/HKT";
import type { Fix } from "static-land-recursion-schemes/lib/Fix";
import { In } from "static-land-recursion-schemes/lib/Fix";
import { Paren } from "./functorized-expression-ast";
@josephjunker
josephjunker / expression-ast.js
Created July 29, 2017 02:10
Expr recursion scheme example
// @flow
import type { Functor } from "flow-static-land/lib/Functor";
import type { HKT } from "flow-static-land/lib/HKT";
import type { Fix } from "static-land-recursion-schemes/lib/Fix";
import { In } from "static-land-recursion-schemes/lib/Fix";
export type ExprI<A>
= Plus<A>
@josephjunker
josephjunker / holePartial.js
Created June 25, 2017 01:31
partial function application with holes
function partialFactory() {
const hole = {};
function mergeArgs(unmerged, merged, args) {
return (
!unmerged.length && !args.length ? merged
: !args.length ? mergeArgs(unmerged.slice(1), merged.concat([unmerged[0]]), args)
: !unmerged.length ? mergeArgs(unmerged, merged.concat([args[0]]), args.slice(1))
: unmerged[0] === hole ? mergeArgs(unmerged.slice(1), merged.concat([args[0]]), args.slice(1))
: /* unmerged is not a hole */ mergeArgs(unmerged.slice(1), merged.concat([unmerged[0]]), args));
@josephjunker
josephjunker / bad-fib.js
Created November 5, 2015 23:39
an even worse fibbonacci sequence generator
function fib(count) {
function f(list) { if(!count) return list; x(); count--; return f(list); }
function x() {
var list = f.arguments[0];
list.push((list[list.length - 1] || 1) + (list[list.length - 2] || 0));
}
if (count < 0) count = 0;
return f([]);
@josephjunker
josephjunker / fibbonacci.js
Created November 5, 2015 22:55
I learned a new feature of JS today
function fib() { if(!x()) return z(); return fib(x(), y(), z()); }
function x() { return fib.arguments[0] - 1; }
function y() { return fib.arguments[2] || 0; }
function z() { return (fib.arguments[1] || 0) + (fib.arguments[2] || 1); }
[fib(1), fib(2), fib(3), fib(4), fib(5), fib(6)].join(); // returns '1,1,2,3,5,8'