Beispiel #1
0
        public void BoolContainers()
        {
            StackFrame         defaultTestCaseFrame = GetFrame($"{DefaultModuleName}!TestBoolContainers");
            VariableCollection locals = defaultTestCaseFrame.Locals;

            bool[] expectedArray = new bool[100];
            for (int i = 0, j = 1; i < expectedArray.Length; i += j, j++)
            {
                for (int k = 0; k < j && i < expectedArray.Length; k++, i++)
                {
                    expectedArray[i] = true;
                }
            }

            // C style array
            CodeArray <bool> carray = new CodeArray <bool>(locals["carray"]);

            Assert.Equal(expectedArray, carray);

            // std::array
            std.array <bool> array = new std.array <bool>(locals["array"]);
            Assert.Equal(expectedArray, array);

            // std::vector
            std.vector <bool> vector = new std.vector <bool>(locals["vector"]);
            Assert.True(expectedArray.Length < vector.Reserved);
            Assert.Equal(expectedArray, vector);
            Assert.Equal(expectedArray, vector.ToArray());
        }
Beispiel #2
0
        public void StdAny()
        {
            StackFrame         defaultTestCaseFrame = GetFrame($"{DefaultModuleName}!TestAny");
            VariableCollection locals = defaultTestCaseFrame.Locals;

            // int
            std.any a_int = new std.any(locals["a_int"]);
            Assert.True(a_int.HasValue);
            Assert.Equal("int", a_int.Value.GetCodeType().Name);
            Assert.Equal(1729, (int)a_int.Value);

            // double
            std.any a_double = new std.any(locals["a_double"]);
            Assert.True(a_double.HasValue);
            Assert.Equal("double", a_double.Value.GetCodeType().Name);
            Assert.Equal(3.14, (double)a_double.Value);

            // std::string
            std.any a_string = new std.any(locals["a_string"]);
            Assert.True(a_string.HasValue);
            std.@string s = new std.@string(a_string.Value);
            Assert.Equal("meow", s.Text);

            // std::vector<int>
            std.any a_vector = new std.any(locals["a_vector"]);
            Assert.True(a_vector.HasValue);
            std.vector <int> v = new std.vector <int>(a_vector.Value);
            Assert.Empty(v);

            // std::list<int>
            std.any a_list = new std.any(locals["a_list"]);
            Assert.True(a_list.HasValue);
            std.list <int> l = new std.list <int>(a_list.Value);
            Assert.Empty(l);

            // std::map<int, int>
            std.any a_map = new std.any(locals["a_map"]);
            Assert.True(a_map.HasValue);
            std.map <int, int> m = new std.map <int, int>(a_map.Value);
            Assert.Empty(m);

            // BigTest
            std.any a_bigTest = new std.any(locals["a_bigTest"]);
            Assert.True(a_bigTest.HasValue);
            Assert.Equal("BigTest", a_bigTest.Value.GetCodeType().Name);
            Assert.Equal("meow meow meow", a_bigTest.Value.GetField("text").ToString());

            // std::pair<std::string, double>
            std.any a_pair = new std.any(locals["a_pair"]);
            Assert.True(a_pair.HasValue);
            std.pair <std::@string, double> p = new std.pair <std::@string, double>(a_pair.Value);
            Assert.Equal("meow", p.First.Text);
            Assert.Equal(3.14, p.Second);

            // std::shared_ptr<std::any>
            std.any a_shared = new std.any(locals["a_shared"]);
            Assert.True(a_shared.HasValue);
            std.shared_ptr <std.any> sp = new std.shared_ptr <std.any>(a_shared.Value);
            Assert.False(sp.IsEmpty);
            std.any inner = sp.Element;
            Assert.True(inner.HasValue);
            p = new std.pair <std::@string, double>(inner.Value);
            Assert.Equal("meow", p.First.Text);
            Assert.Equal(3.14, p.Second);

            // empty
            std.any a_empty = new std.any(locals["a_empty"]);
            Assert.False(a_empty.HasValue);
        }