Example #1
0
    static Sprites()
    {
        var random = new Random(RandSeed);

        //AddErrorCases(random);

        var testSizes = CommonSizes.SortF(new SizeComparer());

        foreach (var size in testSizes)
        {
            //DataSets.Add(MakeAlignedSprite(random, size));
        }

        Vector2I outerSize = (1024, 1024);

        foreach (var size in testSizes)
        {
            var tempOuterSize = outerSize;
            if (size.X >= tempOuterSize.X)
            {
                tempOuterSize.X = NextPower2(size.X + 1);
            }
            if (size.Y >= tempOuterSize.Y)
            {
                tempOuterSize.Y = NextPower2(size.Y + 1);
            }

            DataSets.Add(MakeUnalignedSprite(random, tempOuterSize, size));
        }


        if (Program.CurrentOptions.DoValidate)
        {
            bool error = false;
            Console.WriteLine("Performing Validation...");

            var referenceInstance = new Sprites();

            foreach (var dataSet in DataSets)
            {
                try {
                    ulong baseline = referenceInstance.Baseline(dataSet);

                    foreach (var hasher in new TestFunction[] {
                        referenceInstance.Copy,
                        referenceInstance.SegmentedSpan,
                        referenceInstance.SegmentedSpanExperimental
                    })
                    {
                        ulong hash = hasher(dataSet);
                        if (baseline != hash)
                        {
                            Console.Error.WriteLine($"{hasher.Method.Name} mismatch [{dataSet}]: {hash} != {baseline}");
                            error = true;
                        }
                    }
                }
                catch (Exception ex) {
                    Console.Error.WriteLine($"Exception validating {dataSet}: {ex.GetType().Name} {ex.Message}");
                    error = true;
                }
            }

            if (error)
            {
                throw new Exception("Benchmark validation failed");
            }
        }
    }