Esempio n. 1
0
        static void ExceptionTraceIsCorrect(bool reallyDie, Exception e, ICollection <string> patterns)
        {
            if (reallyDie)
            {
                Fail("expected failure did not occur");
            }
            if (O.isEmpty(patterns))
            {
                Bomb.toss("expected failure occurred, provide regex to Bombs\nEXPECTED:" + e);
            }
            var exceptions = O.list <Exception>();

            exceptions.Add(e);
            while (e != e.GetBaseException())
            {
                e = e.GetBaseException();
                exceptions.Add(e);
            }
            var messages = O.convert(exceptions, anE => anE.Message);

            try {
                Bomb.when(
                    patterns.Count > exceptions.Count,
                    () => "exception stack not deep enough for " + patterns.Count + " patterns:\n" + e
                    );
                O.each(patterns, messages, Matches);
            } catch (Exception matchFailed) {
                Bomb.toss("expected patterns:\n" + O.toShortString(patterns) +
                          "\ndid not match exception messages:\n" + O.toShortString(messages), matchFailed);
            }
        }
Esempio n. 2
0
        public static double standardDeviation(IEnumerable <double> doubles)
        {
            var mean  = average(doubles);
            var sum   = 0.0;
            var count = -1;

            each(doubles, d => { sum += Math.Pow(d - mean, 2); count++; });
            Bomb.when(count == -1, () => "cannot take standard deviation of empty list");
            return(count == 0 ? 0 : Math.Sqrt(sum / count));
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
        public static double populationStandardDeviation(IEnumerable <double> doubles)
        {
            var sum        = 0.0;
            var sumSquares = 0.0;
            var count      = 0;

            each(doubles, d => { sum += d; sumSquares += d * d; count++; });
            Bomb.when(count == 0, () => "cannot take population standard deviation of empty list");
            var average = sum / count;

            return(Math.Sqrt(sumSquares / count - average * average));
        }
Esempio n. 5
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;
        }
Esempio n. 6
0
        public static void each <T1, T2>(IEnumerable <T1> ones, IEnumerable <T2> twos, Action <int, T1, T2> run)
        {
            var twosEnum = twos.GetEnumerator();

            each(
                ones,
                delegate(int i, bool last, T1 one) {
                if (!twosEnum.MoveNext())
                {
                    Bomb.toss(mismatched(ones, twos));
                }
                run(i, one, twosEnum.Current);
            });
            Bomb.when(twosEnum.MoveNext(), () => mismatched(ones, twos));
        }
Esempio n. 7
0
        [Test] public void testParallelEach()
        {
            string[] content = { "" };
            O.each(
                LETTERS,
                START,
                delegate(int i, string s, int val) {
                content[0] += i + ":" + s + "(" + val + ")";
                O.info(i + ":" + s + "(" + val + ")");
            });
            AreEqual("0:a(5)1:b(6)2:c(7)", content[0]);
            content[0] = "";
            O.each(LETTERS, START, delegate(string s, int val) { content[0] += s + "(" + val + ")"; });
            AreEqual("a(5)b(6)c(7)", content[0]);
            Bombs(() => O.each(O.list(1, 2, 3, 4), O.list(2, 3, 4), delegate(int i1, int i2) { }),
                  "failed",
                  "mismatched");
            Bombs(() => O.each(O.list(1, 2, 3), O.list(1, 2, 3, 4), delegate(int i1, int i2) { }), "mismatched");

            Bombs(() => O.each(O.list(4, 5, 6), val => Bomb.when(val == 5, () => "VALUE IS 5!")),
                  "failed@1, processing: 5 in \\[4, 5, 6\\]", "VALUE IS 5");
        }
Esempio n. 8
0
 static void requireNonEmpty <T>(IList <T> ts)
 {
     Bomb.when(Bomb.ifNull(ts, () => "null ts!").Count < 1, () => "empty list passed to requireNonEmpty");
 }
Esempio n. 9
0
 long bytesUsed()
 {
     Bomb.when(started, () => "eek! in the middle of an operation");
     return(totalMemoryUsed);
 }