예제 #1
0
        public void Complex1()
        {
            string line = "Z11 G22 ; hoge";
            var    test = new LineCommand();

            Assert.AreEqual(test.Parse(line), true);
            Assert.AreEqual(test.Comment, "; hoge");
            Assert.AreEqual(test.Original, line);
            Assert.AreEqual(test.Count, 2);
            {
                Double value;
                int    pos;
                Assert.AreEqual(test.TryGetValue('G', out value, out pos), true);
                Assert.AreEqual(value, 22);
                Assert.AreEqual(pos, 1);
                Assert.AreEqual(test.GetFP('G'), 0);
            }
            {
                Double value;
                int    pos;
                Assert.AreEqual(test.TryGetValue('Z', out value, out pos), true);
                Assert.AreEqual(value, 11);
                Assert.AreEqual(pos, 0);
                Assert.AreEqual(test.GetFP('Z'), 0);
            }
            {
                Double value;
                int    pos;
                Assert.AreEqual(test.TryGetValue('A', out value, out pos), false);
                Assert.AreEqual(test.GetFP('A'), 0);
            }
        }
예제 #2
0
        public void Value2()
        {
            string line = "G1.0";
            var    test = new LineCommand();

            Assert.AreEqual(test.Parse(line), true);
            Assert.AreEqual(test.Comment, null);
            Assert.AreEqual(test.Original, line);
            Assert.AreEqual(test.Count, 1);
            {
                Double value;
                int    pos;
                Assert.AreEqual(test.TryGetValue('G', out value, out pos), true);
                Assert.AreEqual(value, 1.0);
                Assert.AreEqual(pos, 0);
                Assert.AreEqual(test.GetFP('G'), 1);
                Assert.AreEqual(test.Has('G'), true);
            }
            {
                Double value;
                int    pos;
                Assert.AreEqual(test.TryGetValue('A', out value, out pos), false);
                Assert.AreEqual(test.GetFP('A'), 0);
                Assert.AreEqual(test.Has('A'), false);
            }
        }
예제 #3
0
        public void CloneValues1()
        {
            string line = "G11.1 Z22.22";
            var    test = new LineCommand();

            Assert.AreEqual(test.Parse(line), true);
            Assert.AreEqual(test.Comment, null);
            Assert.AreEqual(test.Original, line);
            Assert.AreEqual(test.Count, 2);

            var val = test.CloneValues();

            Assert.AreEqual(val.Count, 2);
            Assert.AreEqual(val[0].Key, 'G');
            Assert.AreEqual(val[0].Value, 11.1);
            Assert.AreEqual(val[0].FP, 1);
            Assert.AreEqual(val[0].Position, 0);
            Assert.AreEqual(val[1].Key, 'Z');
            Assert.AreEqual(val[1].Value, 22.22);
            Assert.AreEqual(val[1].FP, 2);
            Assert.AreEqual(val[1].Position, 1);

            // CloneValuesでもらったデータを変更したら、オリジナル側が変わっていないことも確認
            val[0].Value    = 22.3;
            val[0].FP       = 0;
            val[0].Position = 1;
            val[1].Value    = 33.3;
            val[1].FP       = 0;
            val[1].Position = 0;

            {
                Double value;
                int    pos;
                Assert.AreEqual(test.TryGetValue('G', out value, out pos), true);
                Assert.AreEqual(value, 11.1);
                Assert.AreEqual(pos, 0);
                Assert.AreEqual(test.GetFP('G'), 1);
            }
            {
                Double value;
                int    pos;
                Assert.AreEqual(test.TryGetValue('Z', out value, out pos), true);
                Assert.AreEqual(value, 22.22);
                Assert.AreEqual(pos, 1);
                Assert.AreEqual(test.GetFP('Z'), 2);
            }
            {
                Double value;
                int    pos;
                Assert.AreEqual(test.TryGetValue('A', out value, out pos), false);
                Assert.AreEqual(test.GetFP('A'), 0);
            }
        }
예제 #4
0
        public void Add1()
        {
            var test = new LineCommand();

            Assert.AreEqual(test.Add('G', 10.1, 1), true);
            {
                Double value;
                int    pos;
                Assert.AreEqual(test.TryGetValue('G', out value, out pos), true);
                Assert.AreEqual(value, 10.1);
                Assert.AreEqual(pos, 0);
                Assert.AreEqual(test.GetFP('G'), 1);
            }
        }
예제 #5
0
        public void Add3()
        {
            var line = "G10.00";
            var test = new LineCommand();

            test.Parse(line);
            Assert.AreEqual(test.Add('G', 10.1, 1), false);
            {
                Double value;
                int    pos;
                Assert.AreEqual(test.TryGetValue('G', out value, out pos), true);
                Assert.AreEqual(value, 10.0);
                Assert.AreEqual(pos, 0);
                Assert.AreEqual(test.GetFP('G'), 2);
            }
        }
예제 #6
0
        public bool ActionLine(LineCommand line)
        {
            bool   hasXY = line.Has('X') || line.Has('Y');
            bool   hasZ  = line.Has('Z');
            Double prevE = current_.E;

            if (current_.ActionLine(line))
            {
                Double value;
                int    position;
                if (line.TryGetValue('G', out value, out position))
                {
                    switch (value)
                    {
                    case 92:
                        if (line.Has('E'))
                        {
                            totalE_ += prevE;
                        }
                        break;

                    case 1:
                        if (hasXY)
                        {
                            totalLength_ += prev_.LengthXYTo(current_);
                            totalTime_   += prev_.LengthXYTo(current_) / current_.F;
                        }
                        if (hasZ)
                        {
                            totalLength_ += prev_.LengthZTo(current_);
                            totalTime_   += prev_.LengthZTo(current_) / current_.F;
                        }
                        break;
                    }
                }
                prev_.Update(current_);
                return(true);
            }
            return(false);
        }
예제 #7
0
        public void Values6()
        {
            string line = "G1 Z5.5";
            var    test = new LineCommand();

            Assert.AreEqual(test.Parse(line), true);
            Assert.AreEqual(test.Modify('A', (x) => {
                x.Value = 5;
            }), false);
            Assert.AreEqual(test.Modify('G', (x) => {
                x.Value    = 5;
                x.FP       = 1;
                x.Position = 2;
            }), true);
            {
                Double value;
                int    pos;
                Assert.AreEqual(test.TryGetValue('G', out value, out pos), true);
                Assert.AreEqual(value, 5);
                Assert.AreEqual(pos, 2);
                Assert.AreEqual(test.GetFP('G'), 1);
            }
        }