Пример #1
0
        public void TestWashes()
        {
            int[] pile = new int[] { 2, 1, 1, 1, 3, 3, 3, 4, 4 };

            List <int[]> washed = new ClassLib().batchOfWashes(3, pile);

            Assert.Equal(3, washed.Count);
        }
Пример #2
0
        static void Main(string[] args)
        {
            var classLib = new ClassLib();

            int[] cleanPile = new int[] { 1, 2, 3, 1, 2, 3 };
            int[] dirtyPile = new int[] { 3, 3, 4, 1, 2, 7, 9 };
            classLib.GetMaximumPairOfSocks(2, cleanPile, dirtyPile);
            Console.WriteLine("SocksLaundry");
        }
Пример #3
0
        static void Main(string[] args)
        {
            //Set; Get;
            SetGetConstructor d = new SetGetConstructor()
            {
                Name = "Alma", Age = 45
            };

            Console.WriteLine(d.Name + " " + d.Age);

            // reference params
            RefValue r = new RefValue();
            int      x = 2;
            int      y = 10;

            Console.WriteLine(x + " " + y);
            r.ChangeValues(ref x, ref y);
            Console.WriteLine(x + " " + y);

            // object parameter
            ParamsObject p = new ParamsObject();

            p.PrintElements("one", "two");

            // default params
            DefaultParams dp = new DefaultParams(firstName: "Zsolt", lastName: "Annár", job: "UI");

            //dp.FirstName = "oké";
            Console.WriteLine(dp.FirstName);

            // Extended Method
            string s = "mystring";

            s.Print();
            ExtendedMethode.Print(s);

            // Class Library
            ClassLib.PrintHello();

            //PowFunction(x,y)
            double result = PowFunction.Pow(2, 10);

            result.Print();

            //Interface
            IAnimal anim = new Animal()
            {
                Age  = 15,
                Name = "Alma"
            };

            Console.WriteLine(anim.Name);


            Console.ReadKey();
        }
Пример #4
0
        public void Test10()
        {
            int numberMachineCanWash = 50;

            int[] cleanPile = new int[] { 40, 40, 40, 40, 40, 40, 40, 50, 50, 50, 50, 50 };
            int[] dirtyPile = new int[] { 40, 40, 45, 45, 30, 35, 50, 50, 25, 25, 20, 20 };
            int   pairs     = new ClassLib().GetMaximumPairOfSocks(numberMachineCanWash, cleanPile, dirtyPile);

            Assert.Equal(10, pairs);
        }
Пример #5
0
        public void Tst12()
        {
            int numberMachineCanWash = 20;

            int[] cleanPile = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            int[] dirtyPile = new int[] { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
            int   pairs     = new ClassLib().GetMaximumPairOfSocks(numberMachineCanWash, cleanPile, dirtyPile);

            Assert.Equal(0, pairs);
        }
Пример #6
0
        public void Test18()
        {
            int numberMachineCanWash = 5;

            int[] cleanPile = new int[] { 1, 2, 3, 2, 3, 4, 5 };
            int[] dirtyPile = new int[] { 2, 1, 1, 1, 3, 3, 3, 4, 4, 4, 5, 5, 6, 5, 7, 5, 6 };
            int   pairs     = new ClassLib().GetMaximumPairOfSocks(numberMachineCanWash, cleanPile, dirtyPile);

            Assert.Equal(6, pairs);
        }
Пример #7
0
        public void Test4()
        {
            int numberMachineCanWash = 3;

            int[] cleanPile = new int[] { 1, 2, 1, 1 };
            int[] dirtyPile = new int[] { 1, 4, 3, 2, 4 };
            int   pairs     = new ClassLib().GetMaximumPairOfSocks(numberMachineCanWash, cleanPile, dirtyPile);

            Assert.Equal(3, pairs);
        }
Пример #8
0
        public void Test5()
        {
            int numberMachineCanWash = 2;

            int[] cleanPile = new int[] { 1, 2, 3, 1, 2, 3 };
            int[] dirtyPile = new int[] { 3, 3, 4, 1, 2, 7, 9 };
            int   pairs     = new ClassLib().GetMaximumPairOfSocks(numberMachineCanWash, cleanPile, dirtyPile);

            Assert.Equal(4, pairs);
        }
Пример #9
0
        public void Test7()
        {
            int numberMachineCanWash = 0;

            int[] cleanPile = new int[] { 1 };
            int[] dirtyPile = new int[] { 1, 2, 3, 4, 5, 5 };
            int   pairs     = new ClassLib().GetMaximumPairOfSocks(numberMachineCanWash, cleanPile, dirtyPile);

            Assert.Equal(0, pairs);
        }
Пример #10
0
        public void Test8()
        {
            int numberMachineCanWash = 20;

            int[] cleanPile = new int[] { 50, 50, 50, 37, 38, 37, 49, 39, 38, 45, 43 };
            int[] dirtyPile = new int[] { 50 };
            int   pairs     = new ClassLib().GetMaximumPairOfSocks(numberMachineCanWash, cleanPile, dirtyPile);

            Assert.Equal(4, pairs);
        }
Пример #11
0
        static void Main(string[] args)
        {
            int numberMachineCanWash = 5;

            int[] cleanPile = new int[] { 1, 2, 3, 2, 3, 4, 5 };
            int[] dirtyPile = new int[] { 2, 1, 1, 1, 3, 3, 3, 4, 4, 4, 5, 5, 6, 5, 7, 5, 6 };
            int   pairs     = new ClassLib().GetMaximumPairOfSocks(numberMachineCanWash, cleanPile, dirtyPile);

            Console.WriteLine(pairs);
        }
Пример #12
0
        public void Test11()
        {
            int numberMachineCanWash = 1;

            int[] cleanPile = new int[] { 8 };
            int[] dirtyPile = new int[] { 8 };
            int   pairs     = new ClassLib().GetMaximumPairOfSocks(numberMachineCanWash, cleanPile, dirtyPile);

            Assert.Equal(1, pairs);
        }
Пример #13
0
        public LuaValue New(LuaValue[] args)
        {
            if (Static)
            {
                throw new Exception("Cannot create an instance of a static class!");
            }
            LuaClass n = ClassLib.CreateInstance(new LuaValue[] { this }) as LuaClass;

            n.Constructor.Invoke(args);
            return(n);
        }
Пример #14
0
        // creates a subclass inheriting all args except arg[1] if its a table
        // e.g. x = c:CreateSubclass()
        public LuaValue CreateSubClass(LuaValue[] args)
        {
            List <LuaValue> args2 = new List <LuaValue>();

            foreach (LuaValue a in args)
            {
                args2.Add(a);
            }
            args2.Add(this);
            return(ClassLib.CreateClass(args));
        }
Пример #15
0
        static void Main(string[] args)
        {
            int numberMachineCanWash = 2;

            int[] cleanPile = new int[] { 1, 2, 1, 1 };
            int[] dirtyPile = new int[] { 1, 4, 3, 2, 4 };
            int   pairs     = new ClassLib().GetMaximumPairOfSocks(numberMachineCanWash, cleanPile, dirtyPile);

            Console.WriteLine(pairs);
            Console.ReadKey();
        }
Пример #16
0
        public void TestGetPairsOfSocks()
        {
            List <int[]> washes = new List <int[]>();

            washes.Add(new int[] { 5, 6, 9, 8 });
            washes.Add(new int[] { 5, 6, 9, 2 });
            washes.Add(new int[] { 0, 1, 1, 3 });

            int[] pairs = new ClassLib().getPairsOfSocks(washes);

            Assert.Equal(4, pairs.Length);
        }
Пример #17
0
        public LuaValue CallMethod(LuaValue[] args)
        {
            //(func, ...)
            // strip method name
            string          func  = args[0].Value.ToString();
            List <LuaValue> args2 = new List <LuaValue>();

            if ((args[1] as LuaUserdata) != null)
            {
                foreach (LuaValue a in ((args[1] as LuaUserdata).Value as LuaValue[]))
                {
                    args2.Add(a);
                }
            }
            else
            {
                foreach (LuaValue a in args)
                {
                    args2.Add(a);
                }
            }
            try
            {
                args2.RemoveAt(0);
            }
            catch
            {
            }
            LuaFunction f = ClassLib.FindMethod(new LuaValue[] { new LuaString(func), this }) as LuaFunction;

            if ((f == null))
            {
                f = InternalCallParentMethod(func) as LuaFunction;
            }
            // if its still LuaNil.Nil then throw an error
            if ((f == null))
            {
                throw new Exception("Cannot find function '" + func + "'!");
            }

            return(f.Invoke(args2.ToArray()));
        }
Пример #18
0
        public LuaValue InternalCallParentMethod(string method)
        {
            LuaValue m = LuaNil.Nil;

            if (ParentClasses.Count > 0)
            {
                foreach (LuaClass c in ParentClasses)
                {
                    m = ClassLib.FindMethod(new LuaValue[] { new LuaString(method), c });
                    if (m != null)
                    {
                        break;
                    }
                }
            }
            if (m == LuaNil.Nil)
            {
                for (int i = 0; i < ParentClasses.Count; i++)
                {
                    m = ParentClasses[i].InternalCallParentMethod(method);
                }
            }
            return(m);
        }
Пример #19
0
        /// <summary>
        /// Creates a global environment with all the base modules registered and
        /// some default values set.
        /// </summary>
        /// <returns></returns>
        public static LuaTable CreateGlobalEnviroment(bool createBaseLib       = true,
                                                      bool createStringLib     = true,
                                                      bool createTableLib      = true,
                                                      bool createOSLib         = true,
                                                      bool createIOLib         = true,
                                                      bool createFileLib       = true,
                                                      bool createMathLib       = true,
                                                      bool createScriptLib     = true,
                                                      bool createWinFormsLib   = true,
                                                      bool createConsoleLib    = true,
                                                      bool createCoroutineLib  = true,
                                                      bool createPackageLib    = true,
                                                      bool createClassLib      = true,
                                                      bool createFileSystemLib = true)
        {
            LuaTable global = new LuaTable();

            // Register Lua Modules

            if (createBaseLib)
            {
                BaseLib.RegisterFunctions(global);
            }
            if (createStringLib)
            {
                StringLib.RegisterModule(global);
            }
            if (createTableLib)
            {
                TableLib.RegisterModule(global);
            }
            if (createIOLib)
            {
                IOLib.RegisterModule(global);
            }
            if (createFileLib)
            {
                FileLib.RegisterModule(global);
            }
            if (createMathLib)
            {
                MathLib.RegisterModule(global);
            }
            if (createOSLib)
            {
                OSLib.RegisterModule(global);
            }
            if (createScriptLib)
            {
                ScriptLib.RegisterModule(global);
            }
            //if (createWinFormsLib)
            //    WinFormLib.RegisterModule(global);
            if (createConsoleLib)
            {
                ConsoleLib.RegisterModule(global);
            }
            if (createCoroutineLib)
            {
                CoroutineLib.RegisterModule(global);
            }
            if (createPackageLib)
            {
                PackageLib.RegisterModule(global);
            }
            if (createClassLib)
            {
                ClassLib.RegisterModule(global);
            }
            if (createFileSystemLib)
            {
                FileSystemLib.RegisterModule(global);
            }

            //global.SetNameValue("_WORKDIR", new LuaString(Application.StartupPath + "\\"));
            global.SetNameValue("_VERSION", new LuaString("Sharp Lua 1.1"));
            global.SetNameValue("_G", global);

            if (createPackageLib)
            {
                // set package.preload table
                LuaTable preload = (LuaTable)(global.GetValue("package") as LuaTable).GetValue("preload");
                if (createStringLib)
                {
                    preload.SetNameValue("string", (LuaTable)global.GetValue("string"));
                }
                if (createTableLib)
                {
                    preload.SetNameValue("table", (LuaTable)global.GetValue("table"));
                }
                if (createIOLib)
                {
                    preload.SetNameValue("io", (LuaTable)global.GetValue("io"));
                }
                if (createFileLib)
                {
                    preload.SetNameValue("file", (LuaTable)global.GetValue("file"));
                }
                if (createMathLib)
                {
                    preload.SetNameValue("math", (LuaTable)global.GetValue("math"));
                }
                if (createOSLib)
                {
                    preload.SetNameValue("os", (LuaTable)global.GetValue("os"));
                }
                if (createScriptLib)
                {
                    preload.SetNameValue("script", (LuaTable)global.GetValue("script"));
                }
                //if (createWinFormsLib)
                //    preload.SetNameValue("WinForms", (LuaTable) global.GetValue("WinForms"));
                if (createConsoleLib)
                {
                    preload.SetNameValue("console", (LuaTable)global.GetValue("console"));
                }
                if (createCoroutineLib)
                {
                    preload.SetNameValue("coroutine", (LuaTable)global.GetValue("coroutine"));
                }
                if (createPackageLib) // wait a second...
                {
                    preload.SetNameValue("package", (LuaTable)global.GetValue("package"));
                }
                if (createClassLib)
                {
                    preload.SetNameValue("class", (LuaTable)global.GetValue("class"));
                }
                if (createFileSystemLib)
                {
                    preload.SetNameValue("filesystem", (LuaTable)global.GetValue("filesystem"));
                }
            }
            if (createFileSystemLib)
            {
                FileSystemLib.currentDir = global.GetValue("_WORKDIR").ToString();
            }

            GlobalEnvironment = global;
            return(global);
        }
Пример #20
0
 public static SelectList GetInstanceList(ClassLib.Abstract.IService.IInstanceService instanceService)
 {
     return new SelectList(instanceService.Get(), "Id", "Name");
 }
Пример #21
0
 public MyController(ClassLib mylib) => MyLib = mylib;
Пример #22
0
 public LuaValue HasMember(LuaValue[] args)
 { //(m)
     return(ClassLib.IsMemberOf(new LuaValue[] { args[0], this }));
 }
Пример #23
0
        static void Main(string[] args)
        {
            ClassLib cl = new ClassLib();

            Console.WriteLine(cl.Call("Jack"));
        }