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)); }
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); } }
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)); }
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)); }
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); }
public void perftestConvertPerformance() { var dic = new Dictionary <int, int> { { 1, 2 } }; Stopwatch.add("direct", 10000000, delegate { new Dictionary <int, int> { { 1, dic[1] } }; }); Stopwatch.report("direct"); Converter <int, int> nop = i => i; Stopwatch.add("withConvert", 10000000, () => O.convert(dic, nop, nop)); Stopwatch.report("withConvert"); }
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; }