예제 #1
0
        public View BuildViewByModel(Model model)
        {
            View view = new View();

            int  degree    = NumberWork.GetMostRoundingDegree(model.First, model.Second);
            long xArg      = (long)(model.First * NumberWork.Pow(10, degree));
            long yArg      = (long)(model.Second * NumberWork.Pow(10, degree));
            int  maxLength = NumberWork.GetMaxLength(xArg, yArg);

            view.AddLine(makeIndent(Indent) + xArg);
            view.AddLine(makeIndent(Indent + maxLength - NumberWork.NumLength(yArg)) + yArg);
            view.AddLine(makeIndent(Indent) + makeLine(maxLength));

            foreach (var component in model.Components)
            {
                view.AddLine(makeIndent(Indent + maxLength - NumberWork.NumLength(component)) + component);
            }

            view.AddLine(makeIndent(Indent) + makeLine(maxLength));
            view.AddLine(makeIndent(Indent) + model.Result);

            return(view);
        }
예제 #2
0
        private long[] computeComponents()
        {
            int  degree    = NumberWork.GetMostRoundingDegree(First, Second);
            long xArg      = (long)(First * NumberWork.Pow(10, degree));
            long yArg      = (long)(Second * NumberWork.Pow(10, degree));
            int  maxLength = NumberWork.GetMaxLength(xArg, yArg);

            long[] components = new long[maxLength];

            if (NumberWork.NumLength(xArg) < NumberWork.NumLength(yArg))
            {
                Util.Swap(ref xArg, ref yArg);
            }

            long[] xComps = NumberWork.GetNumberComponents(xArg);
            long[] yComps = NumberWork.GetNumberComponents(yArg);

            for (int i = 0; i < maxLength; i++)
            {
                components[i] = xComps[i] + (i < yComps.Length ? yComps[i] : 0);
            }

            return(components);
        }
예제 #3
0
 public void RoundingDegreeTest()
 {
     Assert.Equal(2, NumberWork.GetMostRoundingDegree(13.6, 12.75));
     Assert.Equal(1, NumberWork.GetMostRoundingDegree(13.6, 10));
     Assert.Equal(0, NumberWork.GetMostRoundingDegree(10, 20));
 }