Exemple #1
0
        public void JsonDeSerialize()
        {
            var serialize          = new laba1.JsonSerializator();
            var deserializedObject = serialize.Deserialize <laba1.Input>(
                "{\"K\":35,\"Sums\":[1,2,3.5,4.8,9.999,99],\"Muls\":[1,2,34,42,34,41243]}");
            var flag  = true;
            var input = new laba1.Input
            {
                K    = 35,
                Sums = new[] { 1m, 2m, 3.5m, 4.8m, 9.999m, 99m },
                Muls = new[] { 1, 2, 34, 42, 34, 41243 },
            };

            if (input.K != deserializedObject.K)
            {
                flag = false;
            }
            for (var i = 0; i < input.Sums.Length; i++)
            {
                if (input.Sums[i] != deserializedObject.Sums[i])
                {
                    flag = false;
                }
            }
            for (var i = 0; i < input.Muls.Length; i++)
            {
                if (input.Muls[i] != deserializedObject.Muls[i])
                {
                    flag = false;
                }
            }
            Assert.AreEqual(flag, true);
        }
Exemple #2
0
        static void Main(string[] args)
        {
            var port       = Console.ReadLine();
            var httpClient = new HttpClient();
            var url        = $"http://127.0.0.1:{port}";

            while (!httpClient.Ping(url))
            {
                ;
            }

            var serializer = new JsonSerializator();
            var input      = serializer.Deserialize <Input>(httpClient.GetInputData(url));

            decimal sumResult    = 0;
            var     sortedInputs = new List <decimal>();

            foreach (var term in input.Sums)
            {
                sumResult += term;
                sortedInputs.Add(term);
            }
            sumResult *= input.K;
            var mulResult = 1;

            foreach (var multiplier in input.Muls)
            {
                mulResult *= multiplier;
                sortedInputs.Add(multiplier);
            }
            sortedInputs.Sort();
            var output = new Output
            {
                SumResult    = sumResult,
                MulResult    = mulResult,
                SortedInputs = sortedInputs.ToArray(),
            };

            httpClient.WriteAnswer(url, AddZeros(serializer.Serialize(output)));
        }