Example #1
0
    private void ChangeCurrencyWithProductPrices()
    {
        if (_attributeSet.AttributesAreNowSet == true)
        {
            _salesCalculator.Quality = _attributeSet.qualityFromAttributes;
            float xDays = _timeSystem.daysPlayedTotal /*- _product.DayCreated*/;



            for (int i = 0; i <= _createProduct.TotalPrices.Count - 1; i++)
            {
                if (_createProduct.TotalPrices.Count < 0)
                {
                    return;
                }

                _salesCalculator.PriceOfProduct = _createProduct.TotalPrices[i];
                _salesCalculator.PriceInvested  = _createProduct.TotalInvested[i];

                float _copiesSold         = _salesCalculator.CopiesSoldByDayX(xDays);
                float moneyMadeFromCopies = _createProduct.TotalPrices[i] * _copiesSold;


                _currencyPerSec.SetText(moneyMadeFromCopies.ToString("F", CultureInfo.InvariantCulture) + "/s $");


                if (_copiesSold > 0)
                {
                    _currencyHandler.ModifyCurrency(moneyMadeFromCopies);
                }
            }
        }
    }
    private void OnDrawGizmos()//graph drawing
    {
        if (salesCalculator == null)
        {
            return;
        }

        //Debug.Log(salesCalculator.CopiesSoldByDayX(1));

        for (float i = 0; i < stepsInGraph - 1; i++)
        {
            float x1 = (i / stepsInGraph) * maxDay;          // small steps on x axis
            float y1 = salesCalculator.CopiesSoldByDayX(x1); //scaler for y axis

            float x2 = ((i + 1) / stepsInGraph) * maxDay;
            float y2 = salesCalculator.CopiesSoldByDayX(x2);

            Gizmos.color = Color.black;
            Gizmos.DrawLine(new Vector3(x1 * xScale, y1 * yScale, 0), new Vector3(x2 * xScale, y2 * yScale, 0));
        }
    }
    public static void TestNoNegativeSales()
    {
        SalesCalculator calculator = new SalesCalculator();

        for (int i = 0; i < 1000; i++)
        {
            calculator.Quality            = Random.Range(0f, 1f);
            calculator.PriceOfProduct     = Random.Range(0f, 100f);
            calculator.PriceInvested      = Random.Range(0f, 100000f);
            calculator.MagnitudeOfQuality = Random.Range(0f, 10f);
            int day = Random.Range(0, 100);

            float result = calculator.CopiesSoldByDayX(day);

            Debug.Assert(result >= 0, "Calculor calculated negative sales for " + calculator.ToString() + " at day " + day + " Value: " + result);
            if (result < 0)
            {
                return;
            }
        }
    }
    public static void TestNoSalesOnCrazyPrice()
    {
        SalesCalculator calculator = new SalesCalculator();

        calculator.PriceOfProduct = 10000;
        float totalSold = 0;

        for (int i = 0; i < 50; i++)
        {
            calculator.Quality            = Random.Range(0f, 1f);
            calculator.PriceInvested      = Random.Range(0, 100000);
            calculator.MagnitudeOfQuality = Random.Range(0f, 1f);

            for (int d = 0; d < 100; d++)
            {
                var copiesSold = calculator.CopiesSoldByDayX(d);
                totalSold += Mathf.Max(0, copiesSold);
            }
        }

        Debug.Assert(totalSold == 0, "Test Failed, sold more then 0 copies -> " + totalSold);
    }