Example #1
0
        public void testConvert()
        {
            var letters = O.list("a", "b", "c");
            var sevens  = O.convert(letters, l => 7);

            AreEqual(O.list(7, 7, 7), O.list(sevens));
        }
Example #2
0
        public void testFilter()
        {
            var numbers = O.list(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
            var odds    = O.list(1, 3, 5, 7, 9);

            AreEqual(odds, O.accept(numbers, i => i % 2 == 1));
        }
Example #3
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);
            }
        }
Example #4
0
 public void testShortString()
 {
     AreEqual("[a, b, c]", O.toShortString(O.list("a", "b", "c")));
     AreEqual("2.34K", O.toShortString(2341));
     AreEqual("2.34u", O.toShortString(.000002341));
     AreEqual("1.00G", O.toShortString(1000002341));
     AreEqual("1.00M", O.toShortString(1002341));
 }
Example #5
0
        protected override void initializeSymbols()
        {
            var names = new List <string>();

            O.zeroTo(5, i => names.Add("sym" + (i + 1)));
            symbols = O.list(O.convert(names, name => new Symbol(name)));
            var series = createEmptyTestSeries();

            O.each(symbols, symbol => setupSymbol(symbol, series));
        }
Example #6
0
        protected override void initializeSymbols()
        {
            base.initializeSymbols();
            var names = new List <string>();

            O.zeroTo(50, i => names.Add("sym" + (i + 1)));
            symbols = O.list(O.convert(names, name => new Symbol(name)));
            O.each(symbols, symbol => insertMarket(symbol.name, 0.0));
            O.each(symbols, symbol => insertSymbol("RC." + symbol.name));
        }
Example #7
0
        void addPoints(string fileName)
        {
            var        csv = new QFile(fileName).csv();
            Collection c   = csv.records();

            foreach (var record in O.list <List>(c))
            {
                addPoint(Double.Parse(O.the(O.list <string>(record))));
            }
        }
Example #8
0
        void populateMarkets(int id)
        {
            List <Symbol>    symbols;
            List <Portfolio> portfolios;

            STO.populateSymbolsPortfolios(details, out symbols, out portfolios);
            var names = O.list(O.convert(portfolios, p => p.name));

            names.AddRange(O.convert(symbols, s => s.name));
            marketBox.populateWithAll(names, false);
        }
Example #9
0
        protected override SystemArguments arguments()
        {
            var parameters = new Parameters {
                { "buyOrSell", 1.0 },
                { "RunMode", (double)RunMode.STO },
                { "RunNumber", 1.0 },
                { "systemId", systemId },
                { "TradeSize", 1.0 },
                { "LeadBars", leadBars() }
            };

            parameters.bePreloaded();
            return(new SystemArguments(O.list(A, B, C, D), O.list(P1, P2), parameters));
        }
Example #10
0
        public void testWeakRefList()
        {
            var b1      = new Bar(1, 1, 1, 1);
            var b2      = new Bar(2, 2, 2, 2);
            var refList = new WeakRefList <Bar> {
                new Bar(0, 0, 0, 0),
                b1,
                b2,
                new Bar(3, 3, 3, 3)
            };

            GC.Collect();
            HasCount(2, O.list <Bar>(refList));
        }
Example #11
0
        [Test] public void testEach()
        {
            var result = new List <string>();

            O.each(LETTERS, result.Add);
            AreEqual(LETTERS, result);
            result.Clear();
            O.eachIt(LETTERS, (i, s) => result.Add(i + " " + s));
            AreEqual(O.list("0 a", "1 b", "2 c"), result);
            int[] sum = { 0 };
            O.eachIt(START, delegate(int i, int val) { sum[0] += val + i; });
            AreEqual(sum[0], 21);
            sum[0] = 0;
            O.eachIt(O.list(7, 8, 9), delegate(int i, int val) { sum[0] += val * i; });
            AreEqual(sum[0], 26);
        }
Example #12
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");
        }
Example #13
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);
        }
Example #14
0
 public void testReverse()
 {
     AreEqual(O.list(4, 3, 2, 1), O.list(O.reverse(Objects.list(1, 2, 3, 4))));
     AreEqual(O.list(O.reverse(O.reverse(Objects.seq(15)))), O.list(O.seq(15)));
 }
Example #15
0
        UIElement filterPanel()
        {
            var result = new QGrid {
                Height = 25
            };

            result.addColumn(200);
            result.addColumn(100);
            result.addColumn(100);
            result.add(new QComboBox("ALL", selected => watcher.setTagFilter(selected), O.list <string>(BloombergTagsTable.TAGS.C_TAG.distinct(Clause.TRUE))));
            result.add(new QCheckBox("Show Zeros", false, setting => watcher.setFilterZeroes(!setting)), 1);
            result.add(new QCheckBox("Show Hidden", false, setting => watcher.setShowHidden(setting)), 2);
            return(result);
        }
Example #16
0
        public void doPlot(IEnumerable <Position> positions)
        {
            clear();
            var closed      = O.accept(positions, position => position.isClosed());
            var pnls        = O.sort(O.convert(closed, toValue));
            var min         = O.first(pnls);
            var max         = O.last(pnls);
            var range       = max - min;
            var bucketCount = Math.Max(Math.Min(150, pnls.Count / 5), 1);
            var blockSize   = Math.Max(1, range / bucketCount);

            if (blockSize == 1)
            {
                bucketCount = (int)range + 1;
            }
            var buckets = O.array(O.nCopies(bucketCount, 0.0));

            O.each(pnls, pnl => {
                var bucket = (int)((pnl - min) / blockSize);
                if (bucket == bucketCount)
                {
                    bucket--;
                }
                buckets[bucket]++;
            });
            var bucketStarts  = O.array(O.convert(buckets, (i, unused) => i * blockSize + min));
            var pnlCount      = O.count(pnls);
            var lowerQuartile = pnls[pnlCount / 4];
            var upperQuartile = pnls[3 * pnlCount / 4];
            var median        = pnls[pnlCount / 2];
            var mean          = O.average(pnls);
            var sd            = O.populationStandardDeviation(pnls);
            var colors        = O.array(O.convert(bucketStarts, (i, bucket) => {
                var isLow    = bucket < median;
                var isBright = bucket <= lowerQuartile || bucket >= upperQuartile;
                if (isLow)
                {
                    return(isBright ? (2.0 / 3.0) : 0.0);
                }
                return(isBright ? 1.0 : (1.0 / 3.0));
            }));
            var points = new PointPairList(bucketStarts, buckets, colors);

            addBars("pnls", O.array(Color.DarkRed, Color.FromArgb(0, 18, 110), Color.Red, Color.FromArgb(0, 60, 255)), points);

            GraphObjList.Add(new LineObj(Color.Lime, 0, 0, 0, 1)
            {
                Location = { CoordinateFrame = CoordType.XScaleYChartFraction },
                Line     = { Style = DashStyle.Dot, Width = 2 }
            });
            GraphObjList.Add(new TextObj(O.join("\n", O.list(
                                                    "min = " + O.prettyNumber(min),
                                                    "25% = " + O.prettyNumber(lowerQuartile),
                                                    "50% = " + O.prettyNumber(median),
                                                    "75% = " + O.prettyNumber(upperQuartile),
                                                    "max = " + O.prettyNumber(max), "",
                                                    "mean = " + O.prettyNumber(mean),
                                                    "sd(pop) = " + O.prettyNumber(sd)
                                                    )), 0.9, 0.12, CoordType.ChartFraction)
            {
                FontSpec = { StringAlignment = StringAlignment.Near }
            });
            BarSettings.MinClusterGap = 0;
            XAxis.Scale.MinGrace      = 0;
            XAxis.Scale.MaxGrace      = 0;
        }
Example #17
0
 protected override SystemArguments arguments()
 {
     return(new SystemArguments(O.list(FOO, BAR), parameters()));
 }
 protected override SystemArguments arguments()
 {
     return(new SystemArguments(O.list(symbol2, symbol3, symbol4, symbol5), parameters()));
 }