protected static V requireAllMatchFirst <U, V>(IEnumerable <U> us, Converter <U, V> toV) { var firstV = toV(first(us)); each(rest(us), u => Bomb.unless(firstV.Equals(toV(u)), () => firstV + " does not match " + toV(u))); return(firstV); }
public static T nth <T>(IEnumerable <T> ts, int n) { Bomb.ifNull(ts, () => "null ts!"); var e = ts.GetEnumerator(); zeroTo(n, i => Bomb.unless(e.MoveNext(), () => "can't get " + (i + 1) + "th of empty enumerable")); return(e.Current); }
public static T first <T>(IEnumerable <T> ts) { Bomb.ifNull(ts, () => "null ts!"); var e = ts.GetEnumerator(); Bomb.unless(e.MoveNext(), () => "can't get first of empty enumerable"); return(e.Current); }
public static void AlmostEqual(double expected, double actual, double tolerance) { var delta = Math.Abs(expected - actual); Bomb.unless( delta < tolerance, () => "expected was not almost equal (" + tolerance + ")\nexpected: " + expected.ToString("n20") + "\nactual : " + actual.ToString("n20") + "\ndelta : " + delta ); }
public static T the <T>(IEnumerable <T> ts) { var e = ts.GetEnumerator(); Bomb.unless(e.MoveNext(), () => "ts is empty"); var result = e.Current; Bomb.when(e.MoveNext(), () => "ts has more than one element: " + toShortString(ts)); return(result); }
public static IEnumerable <T> rest <T>(IEnumerable <T> ts) { Bomb.ifNull(ts, () => "null ts!"); var e = ts.GetEnumerator(); Bomb.unless(e.MoveNext(), () => "can't get rest of empty enumerable"); while (e.MoveNext()) { yield return(e.Current); } }
public void runTimers(DateTime time) { Bomb.unless(time.CompareTo(lastTestTimeRun) > 0, () => "attempting to run timers backwards or rerun the same time, \nlastTestTimeRun is " + ymdHuman(lastTestTimeRun) + "\nthis time: " + ymdHuman(time)); freezeNow(time); LogC.info("run " + Bomb.missing(allowedTimes, time) + " timers " + ymdHuman(time)); var actions = copy(timers.get(time)); timers.remove(time); allowedTimes.Remove(time); Bomb.when(isEmpty(actions), () => "no timers expecting to run on " + ymdHuman(time)); each(actions, action => action()); lastTestTimeRun = time; }
public static void runProcess(string exe, string parameters) { var process = Process.Start(new ProcessStartInfo(exe, parameters) { WindowStyle = ProcessWindowStyle.Hidden }); if (process == null) { throw Bomb.toss("failed to start process \n" + exe + " " + parameters); } process.WaitForExit(); Bomb.unless(process.ExitCode == 0, () => "command returned " + process.ExitCode + ".\n" + exe + " " + parameters); }
static void tryAnotherFile(string destination, string source) { var match = Regex.Match(destination, @"(.*)\.([^\.]+)$"); var extension = match.Groups[2].Value; var everythingElse = match.Groups[1].Value; Bomb.unless(match.Success, () => "log file must have an extension: " + destination); match = Regex.Match(everythingElse, @"(.*)\.(\d+)$"); string nextDestination; if (match.Success) { var number = int.Parse(match.Groups[2].Value) + 1; Bomb.unless(number < 10, () => "log files 1-9 are locked, nowhere to log to!"); var prefix = match.Groups[1].Value; nextDestination = O.join(".", O.list(prefix, "" + number, extension)); } else { nextDestination = everythingElse + ".2." + extension; } setOut(source, nextDestination, true); }
void addTestTimer(DateTime time, Action action) { Bomb.unless(allowedTimes.ContainsKey(time), () => "can't add timer for " + ymdHuman(time) + " call intercept if this time is expected."); timers.get(time).Add(action); }
public T value() { Bomb.unless(isAlive(), () => "tried to access GC'd value of a weakReference"); return((T)reference.Target); }
public static T penultimate <T>(IList <T> ts) { Bomb.unless(ts.Count >= 2, () => "no penultimate in " + toShortString(ts)); return(ts[ts.Count - 2]); }
public static T the <T>(IList <T> ts) { Bomb.unless(ts.Count == 1, () => "ts does not have exactly 1 element. has: " + ts.Count + " elements.\n" + toShortString(ts)); return(ts[0]); }
public static long bytesUsed(string s) { Bomb.unless(memory, () => "can't ask for bytes used, not recording memory data."); return(get(s).bytesUsed()); }