Пример #1
0
        public void Setup()
        {
            IPersistentVector v = LazilyPersistentVector.createOwning(1, 2, 3);

            _obj          = _objWithNullMeta = (IObj)v;
            _expectedType = typeof(LazilyPersistentVector);
        }
Пример #2
0
 public void SetupFixture()
 {
     _proxyType = GenProxy.GenerateProxyClass(
         typeof(Impl1),
         RT.seq(LazilyPersistentVector.createOwning(typeof(I1), typeof(I2))),
         "Impl1_I1I2_42");
 }
        public void CreatingOwningOnParamsReturnsVector()
        {
            IPersistentVector v = LazilyPersistentVector.createOwning(1, 2, 3);

            Expect(v.count(), EqualTo(3));
            Expect(v.nth(0), EqualTo(1));
            Expect(v.nth(1), EqualTo(2));
            Expect(v.nth(2), EqualTo(3));
        }
        public void CreateOnNonEmptyCollectionReturnsVector()
        {
            IPersistentVector v = LazilyPersistentVector.createOwning(new object[] { 1, 2, 3 });

            Expect(v.count(), EqualTo(3));
            Expect(v.nth(0), EqualTo(1));
            Expect(v.nth(1), EqualTo(2));
            Expect(v.nth(2), EqualTo(3));
        }
        public void NthInRangeWorks()
        {
            IPersistentVector v = LazilyPersistentVector.createOwning(1, 2, 3);

            Expect(v.count(), EqualTo(3));
            Expect(v.nth(0), EqualTo(1));
            Expect(v.nth(1), EqualTo(2));
            Expect(v.nth(2), EqualTo(3));
        }
Пример #6
0
        public void NthInRangeWorks()
        {
            IPersistentVector v = LazilyPersistentVector.createOwning(1, 2, 3);

            Expect(v.count()).To.Equal(3);
            Expect(v.nth(0)).To.Equal(1);
            Expect(v.nth(1)).To.Equal(2);
            Expect(v.nth(2)).To.Equal(3);
        }
        public void PopOnNonEmptyWorks()
        {
            IPersistentVector v  = LazilyPersistentVector.createOwning(1, 2, 3);
            IPersistentVector v2 = (IPersistentVector)((IPersistentStack)v).pop();

            Expect(v.count(), EqualTo(3));
            Expect(v.nth(0), EqualTo(1));
            Expect(v.nth(1), EqualTo(2));
            Expect(v.nth(2), EqualTo(3));

            Expect(v2.count(), EqualTo(2));
            Expect(v2.nth(0), EqualTo(1));
            Expect(v2.nth(1), EqualTo(2));
        }
        public void AssocnInRangeModifies()
        {
            IPersistentVector v  = LazilyPersistentVector.createOwning(1, 2, 3);
            IPersistentVector v2 = v.assocN(1, 4);

            Expect(v.count(), EqualTo(3));
            Expect(v.nth(0), EqualTo(1));
            Expect(v.nth(1), EqualTo(2));
            Expect(v.nth(2), EqualTo(3));

            Expect(v2.count(), EqualTo(3));
            Expect(v2.nth(0), EqualTo(1));
            Expect(v2.nth(1), EqualTo(4));
            Expect(v2.nth(2), EqualTo(3));
        }
Пример #9
0
        public void ConsAddsAtEnd()
        {
            IPersistentVector v  = LazilyPersistentVector.createOwning(1, 2, 3);
            IPersistentVector v2 = v.cons(4);

            Expect(v.count()).To.Equal(3);
            Expect(v.nth(0)).To.Equal(1);
            Expect(v.nth(1)).To.Equal(2);
            Expect(v.nth(2)).To.Equal(3);

            Expect(v2.count()).To.Equal(4);
            Expect(v2.nth(0)).To.Equal(1);
            Expect(v2.nth(1)).To.Equal(2);
            Expect(v2.nth(2)).To.Equal(3);
            Expect(v2.nth(3)).To.Equal(4);
        }
        public void ConsAddsAtEnd()
        {
            IPersistentVector v  = LazilyPersistentVector.createOwning(1, 2, 3);
            IPersistentVector v2 = v.cons(4);

            Expect(v.count(), EqualTo(3));
            Expect(v.nth(0), EqualTo(1));
            Expect(v.nth(1), EqualTo(2));
            Expect(v.nth(2), EqualTo(3));

            Expect(v2.count(), EqualTo(4));
            Expect(v2.nth(0), EqualTo(1));
            Expect(v2.nth(1), EqualTo(2));
            Expect(v2.nth(2), EqualTo(3));
            Expect(v2.nth(3), EqualTo(4));
        }
Пример #11
0
        public void AssocnAtEndModifies()
        {
            IPersistentVector v  = LazilyPersistentVector.createOwning(1, 2, 3);
            IPersistentVector v2 = v.assocN(3, 4);

            Expect(v.count()).To.Equal(3);
            Expect(v.nth(0)).To.Equal(1);
            Expect(v.nth(1)).To.Equal(2);
            Expect(v.nth(2)).To.Equal(3);

            Expect(v2.count()).To.Equal(4);
            Expect(v2.nth(0)).To.Equal(1);
            Expect(v2.nth(1)).To.Equal(2);
            Expect(v2.nth(2)).To.Equal(3);
            Expect(v2.nth(3)).To.Equal(4);
        }
Пример #12
0
            //(case* expr shift mask  default map<minhash, [test then]> table-type test-type skip-check?)
            //prepared by case macro and presumed correct
            //case macro binds actual expr in let so expr is always a local,
            //no need to worry about multiple evaluation
            public Expr Parse(ParserContext pcon, object frm)
            {
                ISeq form = (ISeq)frm;

                if (pcon.Rhc == RHC.Eval)
                {
                    return(Compiler.Analyze(pcon, RT.list(RT.list(Compiler.FnOnceSym, PersistentVector.EMPTY, form)), "case__" + RT.nextID()));
                }

                IPersistentVector args = LazilyPersistentVector.create(form.next());

                object         exprForm    = args.nth(0);
                int            shift       = Util.ConvertToInt(args.nth(1));
                int            mask        = Util.ConvertToInt(args.nth(2));
                object         defaultForm = args.nth(3);
                IPersistentMap caseMap     = (IPersistentMap)args.nth(4);
                Keyword        switchType  = (Keyword)args.nth(5);
                Keyword        testType    = (Keyword)args.nth(6);
                IPersistentSet skipCheck   = RT.count(args) < 8 ? null : (IPersistentSet)args.nth(7);

                ISeq             keys     = RT.keys(caseMap);
                int              low      = Util.ConvertToInt(RT.first(keys));
                int              high     = Util.ConvertToInt(RT.nth(keys, RT.count(keys) - 1));
                LocalBindingExpr testexpr = (LocalBindingExpr)Compiler.Analyze(pcon.SetRhc(RHC.Expression), exprForm);


                SortedDictionary <int, Expr> tests = new SortedDictionary <int, Expr>();
                Dictionary <int, Expr>       thens = new Dictionary <int, Expr>();

                foreach (IMapEntry me in caseMap)
                {
                    int    minhash  = Util.ConvertToInt(me.key());
                    object pair     = me.val(); // [test-val then-expr]
                    object first    = RT.first(pair);
                    Expr   testExpr = testType == _intKey
                        ? NumberExpr.Parse(Util.ConvertToInt(first))
                        : (first == null ? Compiler.NilExprInstance : new ConstantExpr(first));

                    tests[minhash] = testExpr;
                    Expr thenExpr;
                    thenExpr       = Compiler.Analyze(pcon, RT.second(pair));
                    thens[minhash] = thenExpr;
                }

                Expr defaultExpr;

                defaultExpr = Compiler.Analyze(pcon, defaultForm);

                return(new CaseExpr(
                           (IPersistentMap)Compiler.SourceSpanVar.deref(),
                           testexpr,
                           shift,
                           mask,
                           low,
                           high,
                           defaultExpr,
                           tests,
                           thens,
                           switchType,
                           testType,
                           skipCheck));
            }
Пример #13
0
        public void NthOutOfRangeLowFails()
        {
            IPersistentVector v = LazilyPersistentVector.createOwning(1, 2, 3);

            Expect(v.nth(-4)).To.Equal(1);
        }
        public void NthOutOfRangeHighFails()
        {
            IPersistentVector v = LazilyPersistentVector.createOwning(1, 2, 3);

            Expect(v.nth(4), EqualTo(1));
        }
        public void CreateOnEmptySeqReturnsEmptyVector()
        {
            IPersistentVector v = LazilyPersistentVector.create(new object[] {});

            Expect(v.count(), EqualTo(0));
        }
Пример #16
0
 protected override object Read(PushbackTextReader r, char leftparen, object opts)
 {
     return(LazilyPersistentVector.create(ReadDelimitedList(']', r, true, opts)));
 }
Пример #17
0
        public void AssocNOutOfRangeLowFails()
        {
            IPersistentVector v = LazilyPersistentVector.createOwning(1, 2, 3);

            v.assocN(-4, 4);
        }
        public void CreateOwningOnNoParamsReturnsEmptyVector()
        {
            IPersistentVector v = LazilyPersistentVector.createOwning();

            Expect(v.count(), EqualTo(0));
        }
 public void PopOnEmptyFails()
 {
     IPersistentVector v  = LazilyPersistentVector.createOwning();
     IPersistentStack  v2 = ((IPersistentStack)v).pop();
 }
 public void AssocNOutOfRangeHighFails()
 {
     IPersistentVector v  = LazilyPersistentVector.createOwning(1, 2, 3);
     IPersistentVector v2 = v.assocN(4, 4);
 }
        public void LengthWorks()
        {
            IPersistentVector v = LazilyPersistentVector.createOwning(1, 2, 3);

            Expect(v.length(), EqualTo(3));
        }