示例#1
0
        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);
        }
示例#2
0
        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);
        }
示例#3
0
        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);
        }
示例#4
0
        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
                );
        }
示例#5
0
        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);
        }
示例#6
0
        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);
            }
        }
示例#7
0
        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;
        }
示例#8
0
        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);
        }
示例#9
0
        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);
        }
示例#10
0
 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);
 }
示例#11
0
 public T value()
 {
     Bomb.unless(isAlive(), () => "tried to access GC'd value of a weakReference");
     return((T)reference.Target);
 }
示例#12
0
 public static T penultimate <T>(IList <T> ts)
 {
     Bomb.unless(ts.Count >= 2, () => "no penultimate in " + toShortString(ts));
     return(ts[ts.Count - 2]);
 }
示例#13
0
 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]);
 }
示例#14
0
 public static long bytesUsed(string s)
 {
     Bomb.unless(memory, () => "can't ask for bytes used, not recording memory data.");
     return(get(s).bytesUsed());
 }