public void Calculate(double firstInput, double secondInput, double output)
 {
     var calculator = new Divide();
     var testResult = calculator.Calculate(firstInput, secondInput);
     var result = output;
     Assert.AreEqual(testResult, result);
 }
 /// <summary>
 /// Creates an Divide command if one has not been allocated.
 /// </summary>
 /// <returns>
 /// Returns an allocated Divide command.
 /// </returns>
 public override Divide createDivideCommand()
 {
     if (divide == null)
     {
         divide = new Divide();
     }// end if
     return divide;
 }
Example #3
0
 /// <summary>
 /// Creates a default instance of the Average object using default instances of the
 /// Sum and Divide objects to calculate the average.
 /// </summary>
 internal Average()
 {
     DivideFunction = new Divide();
     SumFunction = new Sum();
 }
Example #4
0
        public void Parse()
        {
            var current = _reader.BaseStream.Position;

            _reader.BaseStream.Seek(_offset, SeekOrigin.Begin);
            bool parsing     = true;
            bool branched    = false;
            int  branchBytes = 0;

            while (parsing)
            {
                //now reader the instructions
                var type    = _reader.ReadByteAsEnum <InstructionType>();
                var aligned = InstructionAlignment.IsAligned(type);

                if (aligned)
                {
                    var padding = _reader.Align(4);
                    if (padding > 0)
                    {
                        Items.Add(new Padding(padding));
                        if (branched)
                        {
                            branchBytes -= (int)padding;

                            if (branchBytes <= 0)
                            {
                                branched    = false;
                                branchBytes = 0;
                            }
                        }
                    }
                }

                InstructionBase instruction = null;
                List <Value>    parameters  = new List <Value>();

                switch (type)
                {
                case InstructionType.ToNumber:
                    instruction = new ToNumber();
                    break;

                case InstructionType.NextFrame:
                    instruction = new NextFrame();
                    break;

                case InstructionType.Play:
                    instruction = new Play();
                    break;

                case InstructionType.Stop:
                    instruction = new Stop();
                    break;

                case InstructionType.Add:
                    instruction = new Add();
                    break;

                case InstructionType.Subtract:
                    instruction = new Subtract();
                    break;

                case InstructionType.Multiply:
                    instruction = new Multiply();
                    break;

                case InstructionType.Divide:
                    instruction = new Divide();
                    break;

                case InstructionType.Not:
                    instruction = new Not();
                    break;

                case InstructionType.StringEquals:
                    instruction = new StringEquals();
                    break;

                case InstructionType.Pop:
                    instruction = new Pop();
                    break;

                case InstructionType.ToInteger:
                    instruction = new ToInteger();
                    break;

                case InstructionType.GetVariable:
                    instruction = new GetVariable();
                    break;

                case InstructionType.SetVariable:
                    instruction = new SetVariable();
                    break;

                case InstructionType.StringConcat:
                    instruction = new StringConcat();
                    break;

                case InstructionType.GetProperty:
                    instruction = new GetProperty();
                    break;

                case InstructionType.SetProperty:
                    instruction = new SetProperty();
                    break;

                case InstructionType.Trace:
                    instruction = new Trace();
                    break;

                case InstructionType.Delete:
                    instruction = new Delete();
                    break;

                case InstructionType.Delete2:
                    instruction = new Delete2();
                    break;

                case InstructionType.DefineLocal:
                    instruction = new DefineLocal();
                    break;

                case InstructionType.CallFunction:
                    instruction = new CallFunction();
                    break;

                case InstructionType.Return:
                    instruction = new Return();
                    break;

                case InstructionType.NewObject:
                    instruction = new NewObject();
                    break;

                case InstructionType.InitArray:
                    instruction = new InitArray();
                    break;

                case InstructionType.InitObject:
                    instruction = new InitObject();
                    break;

                case InstructionType.TypeOf:
                    instruction = new InitObject();
                    break;

                case InstructionType.Add2:
                    instruction = new Add2();
                    break;

                case InstructionType.LessThan2:
                    instruction = new LessThan2();
                    break;

                case InstructionType.Equals2:
                    instruction = new Equals2();
                    break;

                case InstructionType.ToString:
                    instruction = new ToString();
                    break;

                case InstructionType.PushDuplicate:
                    instruction = new PushDuplicate();
                    break;

                case InstructionType.GetMember:
                    instruction = new GetMember();
                    break;

                case InstructionType.SetMember:
                    instruction = new SetMember();
                    break;

                case InstructionType.Increment:
                    instruction = new Increment();
                    break;

                case InstructionType.CallMethod:
                    instruction = new CallMethod();
                    break;

                case InstructionType.Enumerate2:
                    instruction = new Enumerate2();
                    break;

                case InstructionType.EA_PushThis:
                    instruction = new PushThis();
                    break;

                case InstructionType.EA_PushZero:
                    instruction = new PushZero();
                    break;

                case InstructionType.EA_PushOne:
                    instruction = new PushOne();
                    break;

                case InstructionType.EA_CallFunc:
                    instruction = new CallFunc();
                    break;

                case InstructionType.EA_CallMethodPop:
                    instruction = new CallMethodPop();
                    break;

                case InstructionType.BitwiseXOr:
                    instruction = new BitwiseXOr();
                    break;

                case InstructionType.Greater:
                    instruction = new Greater();
                    break;

                case InstructionType.EA_PushThisVar:
                    instruction = new PushThisVar();
                    break;

                case InstructionType.EA_PushGlobalVar:
                    instruction = new PushGlobalVar();
                    break;

                case InstructionType.EA_ZeroVar:
                    instruction = new ZeroVar();
                    break;

                case InstructionType.EA_PushTrue:
                    instruction = new PushTrue();
                    break;

                case InstructionType.EA_PushFalse:
                    instruction = new PushFalse();
                    break;

                case InstructionType.EA_PushNull:
                    instruction = new PushNull();
                    break;

                case InstructionType.EA_PushUndefined:
                    instruction = new PushUndefined();
                    break;

                case InstructionType.GotoFrame:
                    instruction = new GotoFrame();
                    parameters.Add(Value.FromInteger(_reader.ReadInt32()));
                    break;

                case InstructionType.GetURL:
                    instruction = new GetUrl();
                    parameters.Add(Value.FromString(_reader.ReadStringAtOffset()));
                    parameters.Add(Value.FromString(_reader.ReadStringAtOffset()));
                    break;

                case InstructionType.SetRegister:
                    instruction = new SetRegister();
                    parameters.Add(Value.FromInteger(_reader.ReadInt32()));
                    break;

                case InstructionType.ConstantPool:
                {
                    instruction = new ConstantPool();
                    var count     = _reader.ReadUInt32();
                    var constants = _reader.ReadFixedSizeArrayAtOffset <uint>(() => _reader.ReadUInt32(), count);

                    foreach (var constant in constants)
                    {
                        parameters.Add(Value.FromConstant(constant));
                    }
                }
                break;

                case InstructionType.GotoLabel:
                    instruction = new GotoLabel();
                    parameters.Add(Value.FromString(_reader.ReadStringAtOffset()));
                    break;

                case InstructionType.DefineFunction2:
                {
                    instruction = new DefineFunction2();
                    var name       = _reader.ReadStringAtOffset();
                    var nParams    = _reader.ReadUInt32();
                    var nRegisters = _reader.ReadByte();
                    var flags      = _reader.ReadUInt24();

                    //list of parameter strings
                    var paramList = _reader.ReadFixedSizeListAtOffset <FunctionArgument>(() => new FunctionArgument()
                        {
                            Register  = _reader.ReadInt32(),
                            Parameter = _reader.ReadStringAtOffset(),
                        }, nParams);

                    parameters.Add(Value.FromString(name));
                    parameters.Add(Value.FromInteger((int)nParams));
                    parameters.Add(Value.FromInteger((int)nRegisters));
                    parameters.Add(Value.FromInteger((int)flags));
                    foreach (var param in paramList)
                    {
                        parameters.Add(Value.FromInteger(param.Register));
                        parameters.Add(Value.FromString(param.Parameter));
                    }
                    //body size of the function
                    parameters.Add(Value.FromInteger(_reader.ReadInt32()));
                    //skip 8 bytes
                    _reader.ReadUInt64();
                }
                break;

                case InstructionType.PushData:
                {
                    instruction = new PushData();

                    var count     = _reader.ReadUInt32();
                    var constants = _reader.ReadFixedSizeArrayAtOffset <uint>(() => _reader.ReadUInt32(), count);

                    foreach (var constant in constants)
                    {
                        parameters.Add(Value.FromConstant(constant));
                    }
                }
                break;

                case InstructionType.BranchAlways:
                    instruction = new BranchAlways();
                    if (!branched)
                    {
                        branchBytes = _reader.ReadInt32();
                        parameters.Add(Value.FromInteger(branchBytes));

                        if (branchBytes > 0)
                        {
                            branchBytes += (int)instruction.Size + 1;
                            branched     = true;
                        }
                    }
                    else
                    {
                        parameters.Add(Value.FromInteger(_reader.ReadInt32()));
                    }
                    break;

                case InstructionType.GetURL2:
                    instruction = new GetUrl2();
                    break;

                case InstructionType.DefineFunction:
                {
                    instruction = new DefineFunction();
                    var name = _reader.ReadStringAtOffset();
                    //list of parameter strings
                    var paramList = _reader.ReadListAtOffset <string>(() => _reader.ReadStringAtOffset());

                    parameters.Add(Value.FromString(name));
                    parameters.Add(Value.FromInteger(paramList.Count));
                    foreach (var param in paramList)
                    {
                        parameters.Add(Value.FromString(param));
                    }
                    //body size of the function
                    parameters.Add(Value.FromInteger(_reader.ReadInt32()));
                    //skip 8 bytes
                    _reader.ReadUInt64();
                }
                break;

                case InstructionType.BranchIfTrue:
                    instruction = new BranchIfTrue();
                    if (!branched)
                    {
                        branchBytes = _reader.ReadInt32();
                        parameters.Add(Value.FromInteger(branchBytes));

                        if (branchBytes > 0)
                        {
                            branchBytes += (int)instruction.Size + 1;
                            branched     = true;
                        }
                    }
                    else
                    {
                        parameters.Add(Value.FromInteger(_reader.ReadInt32()));
                    }
                    break;

                case InstructionType.GotoFrame2:
                    instruction = new GotoFrame2();
                    parameters.Add(Value.FromInteger(_reader.ReadByte()));
                    break;

                case InstructionType.EA_PushString:
                    instruction = new PushString();
                    //the constant id that should be pushed
                    parameters.Add(Value.FromString(_reader.ReadStringAtOffset()));
                    break;

                case InstructionType.EA_PushConstantByte:
                    instruction = new PushConstantByte();
                    //the constant id that should be pushed
                    parameters.Add(Value.FromConstant(_reader.ReadByte()));
                    break;

                case InstructionType.EA_GetStringVar:
                    instruction = new GetStringVar();
                    parameters.Add(Value.FromString(_reader.ReadStringAtOffset()));
                    break;

                case InstructionType.EA_SetStringVar:
                    instruction = new SetStringMember();
                    parameters.Add(Value.FromString(_reader.ReadStringAtOffset()));
                    break;

                case InstructionType.EA_GetStringMember:
                    instruction = new GetStringMember();
                    parameters.Add(Value.FromString(_reader.ReadStringAtOffset()));
                    break;

                case InstructionType.EA_SetStringMember:
                    instruction = new SetStringMember();
                    parameters.Add(Value.FromString(_reader.ReadStringAtOffset()));
                    break;

                case InstructionType.EA_PushValueOfVar:
                    instruction = new PushValueOfVar();
                    //the constant id that should be pushed
                    parameters.Add(Value.FromConstant(_reader.ReadByte()));
                    break;

                case InstructionType.EA_GetNamedMember:
                    instruction = new GetNamedMember();
                    parameters.Add(Value.FromConstant(_reader.ReadByte()));
                    break;

                case InstructionType.EA_CallNamedFuncPop:
                    instruction = new CallNamedFuncPop();
                    parameters.Add(Value.FromConstant(_reader.ReadByte()));
                    break;

                case InstructionType.EA_CallNamedFunc:
                    instruction = new CallNamedFunc();
                    parameters.Add(Value.FromConstant(_reader.ReadByte()));
                    break;

                case InstructionType.EA_CallNamedMethodPop:
                    instruction = new CallNamedMethodPop();
                    parameters.Add(Value.FromConstant(_reader.ReadByte()));
                    break;

                case InstructionType.EA_PushFloat:
                    instruction = new PushFloat();
                    parameters.Add(Value.FromFloat(_reader.ReadSingle()));
                    break;

                case InstructionType.EA_PushByte:
                    instruction = new PushByte();
                    parameters.Add(Value.FromInteger(_reader.ReadByte()));
                    break;

                case InstructionType.EA_PushShort:
                    instruction = new PushShort();
                    parameters.Add(Value.FromInteger(_reader.ReadUInt16()));
                    break;

                case InstructionType.End:
                    instruction = new End();

                    if (!branched)
                    {
                        parsing = false;
                    }
                    break;

                default:
                    throw new InvalidDataException("Unimplemented bytecode instruction:" + type.ToString());
                }

                if (instruction != null)
                {
                    instruction.Parameters = parameters;
                    Items.Add(instruction);
                }

                if (branched)
                {
                    branchBytes -= (int)instruction.Size + 1;

                    if (branchBytes <= 0)
                    {
                        branched = false;
                    }
                }
            }
            _reader.BaseStream.Seek(current, SeekOrigin.Begin);
        }
Example #5
0
 protected override IEnumerable <BaseStatement> Visit(Divide div) => Binary(div, (a, b) => new Divide(a, b));
 public void DivisionByZeroTests()
 {
     var calculator = new Divide();
     var result = calculator.Calculate(4, 0);
 }
Example #7
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            IGH_Goo goo   = null;
            Image   image = new Image();

            if (!DA.GetData(0, ref goo))
            {
                return;
            }
            if (!goo.TryGetImage(ref image))
            {
                return;
            }

            int mode = 0;

            DA.GetData(1, ref mode);

            IGH_Goo gooA    = null;
            Bitmap  overlay = new Bitmap(100, 100);

            if (DA.GetData(2, ref gooA))
            {
                if (goo.TryGetBitmap(ref overlay))
                {
                    ;
                }
            }

            double numVal = 1.0;

            DA.GetData(3, ref numVal);

            Filter filter = new Filter();

            switch ((FilterModes)mode)
            {
            case FilterModes.Add:
                filter = new Add(overlay);
                image.Filters.Add(new Add(overlay));
                break;

            case FilterModes.Subtract:
                filter = new Subtract(overlay);
                image.Filters.Add(new Subtract(overlay));
                break;

            case FilterModes.Multiply:
                filter = new Multiply(overlay);
                image.Filters.Add(new Multiply(overlay));
                break;

            case FilterModes.Divide:
                filter = new Divide(overlay);
                image.Filters.Add(new Divide(overlay));
                break;

            case FilterModes.Euclidean:
                filter = new Euclidean(overlay, (int)numVal);
                image.Filters.Add(new Euclidean(overlay, (int)numVal));
                break;

            case FilterModes.FlatField:
                filter = new FlatField(overlay);
                image.Filters.Add(new FlatField(overlay));
                break;

            case FilterModes.Intersect:
                filter = new Intersect(overlay);
                image.Filters.Add(new Intersect(overlay));
                break;

            case FilterModes.Merge:
                filter = new Merge(overlay);
                image.Filters.Add(new Merge(overlay));
                break;

            case FilterModes.Morph:
                filter = new Morph(overlay, numVal);
                image.Filters.Add(new Morph(overlay, numVal));
                break;

            case FilterModes.MoveTowards:
                filter = new MoveTowards(overlay, (int)numVal);
                image.Filters.Add(new MoveTowards(overlay, (int)numVal));
                break;

            case FilterModes.Simple:
                filter = new Simple(overlay, (int)numVal);
                image.Filters.Add(new Simple(overlay, (int)numVal));
                break;
            }

            message = ((FilterModes)mode).ToString();
            UpdateMessage();

            DA.SetData(0, image);
            DA.SetData(1, filter);
        }
Example #8
0
 protected override bool Visit(Divide div) => base.Visit(div.Left) || base.Visit(div.Right);
Example #9
0
    public object CalculateParam(ParleyEnviromentInfo info)
    {
        if (paramaters==null || paramaters.Length==0){
            return null;
        }

        if (paramaters.Length==1 && paramaters[0].StartsWith("\"")){
            return paramaters[0].Substring(1,paramaters[0].Length-2);
        }

        Stack<float> values=new Stack<float>();
        Stack<Operator> operators=new Stack<Operator>();

        bool lastWasTerm=false;
        bool nextTermFlip=false;

        foreach (string p in paramaters){
            bool term="+-*/".IndexOf(p)==-1;
            if (term){
                float v=0;
                if ("0123456789".IndexOf(p.Substring(0,1))!=-1){
                    v=float.Parse(p);
                }else{
                    object o=info.GetEnviromentInfo(p);
                    if (o==null){
                        Debug.LogWarning("Parley could not find the term <"+term+"> from the Enviroment. Substituting 0");
                        v=0;
                    }else{
                        v=float.Parse(o.ToString());
                    }
                }
                if (nextTermFlip){
                    values.Push(-v);
                }else{
                    values.Push(v);
                }
                nextTermFlip=false;
                lastWasTerm=true;
            }else{
                if (lastWasTerm){
                    Operator o=null;
                    if ("+".Equals(p)){
                        o=new Add();
                    } else if ("-".Equals(p)){
                        o=new Subtract();
                    } else if ("*".Equals(p)){
                        o=new Multiply();
                    } else if ("/".Equals(p)){
                        o=new Divide();
                    }

                    while (operators.Count>0 && o.weight>operators.Peek().weight){
                        operators.Pop().Execute(values);
                    }
                    operators.Push(o);

                }else{
                    // Change sign on next term
                    if ("-".Equals(p)){
                        nextTermFlip=true;
                    }
                }
                lastWasTerm=false;
            }
        }
        while (operators.Count>0){
            operators.Pop().Execute(values);
        }
        return values.Pop();
    }
 public override object Visit(Divide divide)
 {
     ValidateBinaryExpression(divide);
     return(base.Visit(divide));
 }
Example #11
0
 public INotificationManager Visit(Divide node)
 {
     return(VisitBinaryExpectedType(node, new Types.IntType()));
 }
 public void TestDivideThrowsDivideByZeroException()
 {
     var operation = new Divide();
     var result = operation.Operate(1, 0);
     Assert.IsNull(result);
 }
Example #13
0
        public static InstructionCollection Parse(Stream input, long instructionsPosition)
        {
            var instructions = new SortedList <int, InstructionBase>();

            using (var helper = new InstructionParseHelper(input, instructionsPosition))
            {
                var reader = helper.GetReader();
                while (helper.CanParse(instructions))
                {
                    //now reader the instructions
                    var instructionPosition = helper.CurrentPosition;
                    var type             = reader.ReadByteAsEnum <InstructionType>();
                    var requireAlignment = InstructionAlignment.IsAligned(type);

                    if (requireAlignment)
                    {
                        reader.Align(4);
                    }

                    InstructionBase instruction = null;
                    var             parameters  = new List <Value>();

                    switch (type)
                    {
                    case InstructionType.ToNumber:
                        instruction = new ToNumber();
                        break;

                    case InstructionType.NextFrame:
                        instruction = new NextFrame();
                        break;

                    case InstructionType.Play:
                        instruction = new Play();
                        break;

                    case InstructionType.Stop:
                        instruction = new Stop();
                        break;

                    case InstructionType.Add:
                        instruction = new Add();
                        break;

                    case InstructionType.Subtract:
                        instruction = new Subtract();
                        break;

                    case InstructionType.Multiply:
                        instruction = new Multiply();
                        break;

                    case InstructionType.Divide:
                        instruction = new Divide();
                        break;

                    case InstructionType.Not:
                        instruction = new Not();
                        break;

                    case InstructionType.StringEquals:
                        instruction = new StringEquals();
                        break;

                    case InstructionType.Pop:
                        instruction = new Pop();
                        break;

                    case InstructionType.ToInteger:
                        instruction = new ToInteger();
                        break;

                    case InstructionType.GetVariable:
                        instruction = new GetVariable();
                        break;

                    case InstructionType.SetVariable:
                        instruction = new SetVariable();
                        break;

                    case InstructionType.StringConcat:
                        instruction = new StringConcat();
                        break;

                    case InstructionType.GetProperty:
                        instruction = new GetProperty();
                        break;

                    case InstructionType.SetProperty:
                        instruction = new SetProperty();
                        break;

                    case InstructionType.Trace:
                        instruction = new Trace();
                        break;

                    case InstructionType.Random:
                        instruction = new RandomNumber();
                        break;

                    case InstructionType.Delete:
                        instruction = new Delete();
                        break;

                    case InstructionType.Delete2:
                        instruction = new Delete2();
                        break;

                    case InstructionType.DefineLocal:
                        instruction = new DefineLocal();
                        break;

                    case InstructionType.CallFunction:
                        instruction = new CallFunction();
                        break;

                    case InstructionType.Return:
                        instruction = new Return();
                        break;

                    case InstructionType.NewObject:
                        instruction = new NewObject();
                        break;

                    case InstructionType.InitArray:
                        instruction = new InitArray();
                        break;

                    case InstructionType.InitObject:
                        instruction = new InitObject();
                        break;

                    case InstructionType.TypeOf:
                        instruction = new TypeOf();
                        break;

                    case InstructionType.Add2:
                        instruction = new Add2();
                        break;

                    case InstructionType.LessThan2:
                        instruction = new LessThan2();
                        break;

                    case InstructionType.Equals2:
                        instruction = new Equals2();
                        break;

                    case InstructionType.ToString:
                        instruction = new ToString();
                        break;

                    case InstructionType.PushDuplicate:
                        instruction = new PushDuplicate();
                        break;

                    case InstructionType.GetMember:
                        instruction = new GetMember();
                        break;

                    case InstructionType.SetMember:
                        instruction = new SetMember();
                        break;

                    case InstructionType.Increment:
                        instruction = new Increment();
                        break;

                    case InstructionType.Decrement:
                        instruction = new Decrement();
                        break;

                    case InstructionType.CallMethod:
                        instruction = new CallMethod();
                        break;

                    case InstructionType.Enumerate2:
                        instruction = new Enumerate2();
                        break;

                    case InstructionType.EA_PushThis:
                        instruction = new PushThis();
                        break;

                    case InstructionType.EA_PushZero:
                        instruction = new PushZero();
                        break;

                    case InstructionType.EA_PushOne:
                        instruction = new PushOne();
                        break;

                    case InstructionType.EA_CallFunc:
                        instruction = new CallFunc();
                        break;

                    case InstructionType.EA_CallMethodPop:
                        instruction = new CallMethodPop();
                        break;

                    case InstructionType.BitwiseXOr:
                        instruction = new BitwiseXOr();
                        break;

                    case InstructionType.Greater:
                        instruction = new Greater();
                        break;

                    case InstructionType.EA_PushThisVar:
                        instruction = new PushThisVar();
                        break;

                    case InstructionType.EA_PushGlobalVar:
                        instruction = new PushGlobalVar();
                        break;

                    case InstructionType.EA_ZeroVar:
                        instruction = new ZeroVar();
                        break;

                    case InstructionType.EA_PushTrue:
                        instruction = new PushTrue();
                        break;

                    case InstructionType.EA_PushFalse:
                        instruction = new PushFalse();
                        break;

                    case InstructionType.EA_PushNull:
                        instruction = new PushNull();
                        break;

                    case InstructionType.EA_PushUndefined:
                        instruction = new PushUndefined();
                        break;

                    case InstructionType.GotoFrame:
                        instruction = new GotoFrame();
                        parameters.Add(Value.FromInteger(reader.ReadInt32()));
                        break;

                    case InstructionType.GetURL:
                        instruction = new GetUrl();
                        parameters.Add(Value.FromString(reader.ReadStringAtOffset()));
                        parameters.Add(Value.FromString(reader.ReadStringAtOffset()));
                        break;

                    case InstructionType.SetRegister:
                        instruction = new SetRegister();
                        parameters.Add(Value.FromInteger(reader.ReadInt32()));
                        break;

                    case InstructionType.ConstantPool:
                    {
                        instruction = new ConstantPool();
                        var count     = reader.ReadUInt32();
                        var constants = reader.ReadFixedSizeArrayAtOffset <uint>(() => reader.ReadUInt32(), count);

                        foreach (var constant in constants)
                        {
                            parameters.Add(Value.FromConstant(constant));
                        }
                    }
                    break;

                    case InstructionType.GotoLabel:
                        instruction = new GotoLabel();
                        parameters.Add(Value.FromString(reader.ReadStringAtOffset()));
                        break;

                    case InstructionType.DefineFunction2:
                    {
                        instruction = new DefineFunction2();
                        var name       = reader.ReadStringAtOffset();
                        var nParams    = reader.ReadUInt32();
                        var nRegisters = reader.ReadByte();
                        var flags      = reader.ReadUInt24();

                        //list of parameter strings
                        var paramList = reader.ReadFixedSizeListAtOffset <FunctionArgument>(() => new FunctionArgument()
                            {
                                Register  = reader.ReadInt32(),
                                Parameter = reader.ReadStringAtOffset(),
                            }, nParams);

                        parameters.Add(Value.FromString(name));
                        parameters.Add(Value.FromInteger((int)nParams));
                        parameters.Add(Value.FromInteger((int)nRegisters));
                        parameters.Add(Value.FromInteger((int)flags));
                        foreach (var param in paramList)
                        {
                            parameters.Add(Value.FromInteger(param.Register));
                            parameters.Add(Value.FromString(param.Parameter));
                        }
                        //body size of the function
                        parameters.Add(Value.FromInteger(reader.ReadInt32()));
                        //skip 8 bytes
                        reader.ReadUInt64();
                    }
                    break;

                    case InstructionType.PushData:
                    {
                        instruction = new PushData();

                        var count     = reader.ReadUInt32();
                        var constants = reader.ReadFixedSizeArrayAtOffset <uint>(() => reader.ReadUInt32(), count);

                        foreach (var constant in constants)
                        {
                            parameters.Add(Value.FromConstant(constant));
                        }
                    }
                    break;

                    case InstructionType.BranchAlways:
                    {
                        instruction = new BranchAlways();
                        var offset = reader.ReadInt32();
                        parameters.Add(Value.FromInteger(offset));
                        helper.ReportBranchOffset(offset);
                    }
                    break;

                    case InstructionType.GetURL2:
                        instruction = new GetUrl2();
                        break;

                    case InstructionType.DefineFunction:
                    {
                        instruction = new DefineFunction();
                        var name = reader.ReadStringAtOffset();
                        //list of parameter strings
                        var paramList = reader.ReadListAtOffset <string>(() => reader.ReadStringAtOffset());

                        parameters.Add(Value.FromString(name));
                        parameters.Add(Value.FromInteger(paramList.Count));
                        foreach (var param in paramList)
                        {
                            parameters.Add(Value.FromString(param));
                        }
                        //body size of the function
                        parameters.Add(Value.FromInteger(reader.ReadInt32()));
                        //skip 8 bytes
                        reader.ReadUInt64();
                    }
                    break;

                    case InstructionType.BranchIfTrue:
                    {
                        instruction = new BranchIfTrue();
                        var offset = reader.ReadInt32();
                        parameters.Add(Value.FromInteger(offset));
                        helper.ReportBranchOffset(offset);
                    }
                    break;

                    case InstructionType.GotoFrame2:
                        instruction = new GotoFrame2();
                        parameters.Add(Value.FromInteger(reader.ReadByte()));
                        break;

                    case InstructionType.EA_PushString:
                        instruction = new PushString();
                        //the constant id that should be pushed
                        parameters.Add(Value.FromString(reader.ReadStringAtOffset()));
                        break;

                    case InstructionType.EA_PushConstantByte:
                        instruction = new PushConstantByte();
                        //the constant id that should be pushed
                        parameters.Add(Value.FromConstant(reader.ReadByte()));
                        break;

                    case InstructionType.EA_GetStringVar:
                        instruction = new GetStringVar();
                        parameters.Add(Value.FromString(reader.ReadStringAtOffset()));
                        break;

                    case InstructionType.EA_SetStringVar:
                        instruction = new SetStringVar();
                        parameters.Add(Value.FromString(reader.ReadStringAtOffset()));
                        break;

                    case InstructionType.EA_GetStringMember:
                        instruction = new GetStringMember();
                        parameters.Add(Value.FromString(reader.ReadStringAtOffset()));
                        break;

                    case InstructionType.EA_SetStringMember:
                        instruction = new SetStringMember();
                        parameters.Add(Value.FromString(reader.ReadStringAtOffset()));
                        break;

                    case InstructionType.EA_PushValueOfVar:
                        instruction = new PushValueOfVar();
                        //the constant id that should be pushed
                        parameters.Add(Value.FromConstant(reader.ReadByte()));
                        break;

                    case InstructionType.EA_GetNamedMember:
                        instruction = new GetNamedMember();
                        parameters.Add(Value.FromConstant(reader.ReadByte()));
                        break;

                    case InstructionType.EA_CallNamedFuncPop:
                        instruction = new CallNamedFuncPop();
                        parameters.Add(Value.FromConstant(reader.ReadByte()));
                        break;

                    case InstructionType.EA_CallNamedFunc:
                        instruction = new CallNamedFunc();
                        parameters.Add(Value.FromConstant(reader.ReadByte()));
                        break;

                    case InstructionType.EA_CallNamedMethodPop:
                        instruction = new CallNamedMethodPop();
                        parameters.Add(Value.FromConstant(reader.ReadByte()));
                        break;

                    case InstructionType.EA_PushFloat:
                        instruction = new PushFloat();
                        parameters.Add(Value.FromFloat(reader.ReadSingle()));
                        break;

                    case InstructionType.EA_PushByte:
                        instruction = new PushByte();
                        parameters.Add(Value.FromInteger(reader.ReadByte()));
                        break;

                    case InstructionType.EA_PushShort:
                        instruction = new PushShort();
                        parameters.Add(Value.FromInteger(reader.ReadUInt16()));
                        break;

                    case InstructionType.End:
                        instruction = new End();
                        break;

                    case InstructionType.EA_CallNamedMethod:
                        instruction = new CallNamedMethod();
                        parameters.Add(Value.FromConstant(reader.ReadByte()));
                        break;

                    case InstructionType.Var:
                        instruction = new Var();
                        break;

                    case InstructionType.EA_PushRegister:
                        instruction = new PushRegister();
                        parameters.Add(Value.FromInteger(reader.ReadByte()));
                        break;

                    case InstructionType.EA_PushConstantWord:
                        instruction = new PushConstantWord();
                        parameters.Add(Value.FromConstant(reader.ReadUInt16()));
                        break;

                    case InstructionType.EA_CallFuncPop:
                        instruction = new CallFunctionPop();
                        break;

                    case InstructionType.StrictEqual:
                        instruction = new StrictEquals();
                        break;

                    default:
                        throw new InvalidDataException("Unimplemented bytecode instruction:" + type.ToString());
                    }

                    if (instruction != null)
                    {
                        instruction.Parameters = parameters;
                        instructions.Add(instructionPosition, instruction);
                    }
                }
            }

            return(new InstructionCollection(instructions));
        }
Example #14
0
 public override void VisitDivide(Divide n)
 {
     VisitBinaryArithmetic(n);
 }
Example #15
0
        private void TreeConstruct(Stack <BaseNode> treeStack, Queue <string> postfixQueue)
        {
            while (postfixQueue.Count > 0)
            {
                string currentPart = postfixQueue.Dequeue();
                if (!string.IsNullOrEmpty(currentPart))
                {
                    // if next queue element is operand, push it to stack
                    if (char.IsLetterOrDigit(currentPart[0]))
                    {
                        // if currentPart is a number.
                        if (char.IsDigit(currentPart[0]))
                        {
                            ConstantNumbericalNode newNode = new ConstantNumbericalNode(Convert.ToDouble(currentPart));
                            treeStack.Push(newNode);
                        }

                        // if currentPart is a string
                        else if (char.IsLetter(currentPart[0]))
                        {
                            VariableNode newNode = new VariableNode(currentPart);
                            treeStack.Push(newNode);
                        }
                    }

                    // if next queue element is operator
                    else if (this.IsOperator(currentPart[0]))
                    {
                        switch (currentPart[0])
                        {
                        case '+':
                            Addition newAdd = new Addition();
                            newAdd.Right = treeStack.Pop();
                            newAdd.Left  = treeStack.Pop();
                            treeStack.Push(newAdd);
                            break;

                        case '-':
                            Minus newMin = new Minus();
                            newMin.Right = treeStack.Pop();
                            newMin.Left  = treeStack.Pop();
                            treeStack.Push(newMin);
                            break;

                        case '*':
                            Multiple newMul = new Multiple();
                            newMul.Right = treeStack.Pop();
                            newMul.Left  = treeStack.Pop();
                            treeStack.Push(newMul);
                            break;

                        case '/':
                            Divide newDiv = new Divide();
                            newDiv.Right = treeStack.Pop();
                            newDiv.Left  = treeStack.Pop();
                            treeStack.Push(newDiv);
                            break;
                        }
                    }
                }
            }
        }
Example #16
0
        //MEMENTO
        //static string path = @"D:\kasia.txt";
        //static WzCzynnosciowe.Memento.Memento memento;
        static void Main(string[] args)
        {
            //    File.WriteAllText(path, "kasia");

            //    //pierwsza instancja memento
            //    if (path != "" && File.Exists(path))
            //    {
            //        memento = new WzCzynnosciowe.Memento.Memento(path, File.ReadAllBytes(path));
            //    }

            //    //zapis nowej wartości do pliku
            //    File.WriteAllText(path, "kasia2");

            //    //przywrócenie z memento
            //    memento.RevertFromMemento();

            //    File.WriteAllText(path, "kasia3");
            //    //nowe dane w obiekcie memento
            //    memento.SetNewData(path);
            //    File.WriteAllText(path, "kasia4");
            //    memento.RevertFromMemento();
            // Console.Read();

            //STATE
            //Context c = new Context(new BigState());
            //Console.ReadLine();
            //c.Change();
            //Console.ReadLine();
            //c.Change();
            //Console.ReadLine();
            //c.Change();
            //Console.Read();

            //STRATEGY
            //Context c = null;
            //while (true)
            //{
            //    var strategy = Console.ReadLine();
            //    switch (strategy)
            //    {
            //        case "N":
            //            c = new Context(new NormalPerson());
            //            break;
            //        case "D":
            //            c = new Context(new Lumberman());
            //            break;
            //        case "K":
            //            c = new Context(new StrongKickPerson());
            //            break;
            //        default:
            //            Console.WriteLine("N - noramlna osoba " +
            //             "D - drwal " +
            //            "K - osoba ktora silnie kopie");
            //            break;
            //    }
            //    if (c != null)
            //    {
            //        foreach (var item in c.Person.Data())
            //        {
            //            Console.WriteLine(item.ToString());
            //        }
            //    }


            //}

            //ITERATOR
            //List<string> MyList = new List<string> { "kasia", "asia", "basia" };
            // ConcreteIterable ci = new ConcreteIterable();
            // ci[0] = "kasia";
            // ci[1] = "basia";
            // ci[2] = "asia";

            // var it = ci.GetIterator();
            // var i = it.First();
            //// Console.WriteLine(it.First());

            // while (!it.IsEnd())
            // {

            //     Console.WriteLine(it.Current());
            //     it.Next();
            //     if (it.IsEnd())
            //     {
            //         Console.WriteLine(it.Current());
            //     }
            // }


            //OBSERWATOR
            //ConcreteSubject s = new ConcreteSubject("kasia");

            //Observer o1 = new ConcreteObserver(s, "obserwator1");
            //Observer o2 = new ConcreteObserver(s, "obserwator2");

            //s.Attach(o1);
            //s.Attach(o2);
            //s.Notify();
            //s.SubjectState = "ania";
            //s.Notify();
            //Console.ReadLine();

            //CHAIN OF RESPONSIBILITY
            //Handler S = new ConcreteHandler1();
            //Handler M = new ConcreteHandler2();
            //Handler R = new ConcreteHandler3();
            //S.SetSuccessor(M);
            //M.SetSuccessor(R);

            //S.HandleRequest(20);
            //Console.ReadLine();

            //Copy&Paste

            //OriginalAnimal oAnimal = new OriginalAnimal("Wodne", "Rybka");
            ////oAnimal.SetAnimalType("Wodne");
            //Console.WriteLine(oAnimal.GetAnimalName());
            //Console.WriteLine(oAnimal.AnimalType);

            ////Tworzymy psa
            //Console.WriteLine();
            ////CopyPasteDogAnimal dog = new CopyPasteDogAnimal("Lądowe", "Jeżyk", 4);

            ////Console.WriteLine(dog.GetAnimalName("Jeży"));

            ////Console.WriteLine(dog.GetAnimalType("Jeży"));

            //Console.Read();

            Divide d = new Divide();

            Console.WriteLine(d.Dziel(4, 2));

            Console.Read();
        }
 protected override bool Visit(Divide div) => Visit(div.Left) && Visit(div.Right);
Example #18
0
 public void TestSimpleDivision()
 {
     var divide = new Divide(new Property("Left"), new Property("Right"));
     Assert.That(divide.Evaluate(new Reflection(this)), Is.EqualTo(7));
 }
Example #19
0
 public override string Visit(Divide node)
 {
     return(VisitBinary("/", node));
 }
Example #20
0
 public AbstractValue Evaluate(Divide expr)
 {
     throw new NotImplementedException();
 }
Example #21
0
 public override Expression On(Divide e)
 {
     return((_.D(e.Left, x) * e.Right - e.Left * _.D(e.Right, x)) / _.Pow(e.Right, 2));
 }
Example #22
0
 public IActionResult DivResults(Divide divide)
 {
     return(View(divide));
 }
        private void DivideByZero()
        {
            Divide calc = new Divide();

            calc.ApplyTo(1, 0);
        }
Example #24
0
 public virtual void VisitDivide(Divide n)
 {
 }
 [NotNull] protected abstract TResult Visit([NotNull] Divide div);
Example #26
0
        public static string sample_divide()
        {
            int dividend = 500;
            int divisor  = 36;

            string ret = string.Empty;

            Action <IDictionary <string, object> > printOutputs = delegate(IDictionary <string, object> outArgs)
            {
                if (outArgs != null)
                {
                    ret = $"{dividend} / {divisor} = {outArgs["Result"]} Remainder {outArgs["Remainder"]}";
                }
            };

            Dictionary <string, object> arguments = new Dictionary <string, object>();

            arguments.Add("Dividend", dividend);
            arguments.Add("Divisor", divisor);

            //IDictionary<string, object> outputs = null;
            //outputs = WorkflowInvoker.Invoke(new Divide(), arguments);
            //printOutputs(outputs);

            Variable <int> res = new Variable <int>();


            AutoResetEvent syncEvent = new AutoResetEvent(false);

            Divide divide = new Divide()
            {
                Variables = { res },
                //Result = new OutArgument<int>(res),
                //Body = new Sequence()
                //{
                //    Activities = {
                //        //new InvokeMethod()
                //        //{
                //        //    MethodName = nameof(Samples.Test),
                //        //    TargetType = typeof(Samples),
                //        //    Parameters = { new InArgument<int>(env => res.Get(env)) }
                //        //}
                //    }
                //}
            };

            var wf = new WorkflowApplication(divide, arguments);

            wf.Completed            = e => { printOutputs(e.Outputs); syncEvent.Set(); };
            wf.Unloaded             = e => { syncEvent.Set(); };
            wf.Aborted              = e => { syncEvent.Set(); };
            wf.Idle                 = e => { syncEvent.Set(); };
            wf.PersistableIdle      = e => { return(PersistableIdleAction.None); };
            wf.OnUnhandledException = e => { return(UnhandledExceptionAction.Terminate); };

            wf.Run(TimeSpan.FromMinutes(1));

            syncEvent.WaitOne();

            return(ret);
        }
Example #27
0
 protected override IDataFlowGraphExpressionNode Visit(Divide div) => VisitBinary(div, YololBinaryOp.Divide);
Example #28
0
 protected override bool Visit(Divide div) => VisitBinary(div);
 public SemanticAtom Visit(Divide n)
 {
     n.RealizedType = BinaryExpressionHelper(n, Primitive.Int, "/", Primitive.Int);
     return(n.RealizedType);
 }
 public IEnumerable <Id> Visit(Divide node)
 {
     return(VisitBinary(node));
 }
Example #31
0
        public void ShouldDivideTwoNumbers()
        {
            var result = new Divide(new Const(10), new Const(5)).GetResult();

            Assert.That(result, Is.EqualTo(2));
        }
        private bool ReadToken(out Token token)
        {
            var currentState = InputState.Start;
            var tokenStr     = new StringBuilder();

            for (; _pos < _expression.Length; _pos++)
            {
                var symbol = _expression[_pos];
                var pair   = _table.Get(new KeyValuePair <InputState, char>(currentState, symbol));

                if (pair.Key == InputState.Start)
                {
                    continue;
                }

                if (pair.Key == InputState.Finish)
                {
                    switch (pair.Value)
                    {
                    case OutputState.Add:
                        token = new Add();
                        Step();
                        return(true);

                    case OutputState.Sub:
                        token = new Substract();
                        Step();
                        return(true);

                    case OutputState.Mul:
                        token = new Multiply();
                        return(true);

                    case OutputState.Div:
                        token = new Divide();
                        Step();
                        return(true);

                    case OutputState.Pow:
                        token = new Power();
                        Step();
                        return(true);

                    case OutputState.LBr:
                        token = new OpenBracket();
                        Step();
                        return(true);

                    case OutputState.RBr:
                        token = new CloseBracket();
                        Step();
                        return(true);

                    case OutputState.LPart:
                        token = new Digit(tokenStr.ToString());
                        return(true);

                    case OutputState.RPart:
                        token = new Digit(tokenStr.ToString());
                        return(true);
                    }
                }
                currentState = pair.Key;
                tokenStr.Append(symbol);
            }
            token = null;
            return(false);
        }
Example #33
0
        // Create Tree from file.
        private TreeElement CreateTreeFromFile
            (System.IO.StreamReader file, TreeElement treeElement)
        {
            int         value = 0;
            TreeElement left  = null;
            TreeElement right = null;

            if (file.EndOfStream)
            {
                return(treeElement);
            }
            int ch = file.Read(); //  '(' или цифра или ' '

            if (ch == ' ')
            {
                ch = file.Read(); //  '(' или цифра
            }
            if (ch == '(')
            {
                ch = file.Read();  // ' '
                if (ch != ' ')
                {
                    throw new ExceptionTree("Waiting ' '.");
                }

                ch = file.Read();  // sign
                if (ch != '+' && ch != '-' && ch != '*' && ch != '/')
                {
                    throw new ExceptionTree("Waiting sign.");
                }

                value = ch;
                ch    = file.Read(); // ' '
                if (ch != ' ')
                {
                    throw new ExceptionTree("Waiting ' '.");
                }

                left  = CreateTreeFromFile(file, left);
                right = CreateTreeFromFile(file, right);

                if (value == '+')
                {
                    treeElement = new Add(value, left, right);
                }
                if (value == '-')
                {
                    treeElement = new Subtract(value, left, right);
                }
                if (value == '*')
                {
                    treeElement = new Multiply(value, left, right);
                }
                if (value == '/')
                {
                    treeElement = new Divide(value, left, right);
                }
                ch = file.Read(); // ')' или ' '
                if (ch == ' ')
                {
                    ch = file.Read(); // ')'
                }
                if (ch != ')')
                {
                    throw new ExceptionTree("Waiting ).");
                }

                /* ch = file.Read(); // ' '
                 * if (ch != ' ')
                 *   throw new ExceptionTree("Waiting ' '."); */
            }

            else if (ch <= '9' && ch >= '0')
            {
                int number = 0;
                while (ch <= '9' && ch >= '0')
                {
                    number = number * 10 + ch - '0';
                    ch     = file.Read();
                }
                if (ch != ' ')
                {
                    throw new ExceptionTree("Waiting ' '.");
                }

                value       = number;
                treeElement = new Value(value);
            }
            else
            {
                throw new ExceptionTree("Waiting '(' or number.");
            }
            return(treeElement);
        }
Example #34
0
        // Create Tree from file.
        private TreeElement CreateTreeFromFile
            (System.IO.StreamReader file, TreeElement treeElement)
        {
            int value = 0;
            TreeElement left = null;
            TreeElement right = null;

            if (file.EndOfStream)
                return treeElement;
            int ch = file.Read(); //  '(' или цифра или ' '
            if (ch == ' ')
                ch = file.Read(); //  '(' или цифра
            if (ch == '(')
            {
                ch = file.Read();  // ' '
                if (ch != ' ')
                    throw new ExceptionTree("Waiting ' '.");

                ch = file.Read();  // sign
                if (ch != '+' && ch != '-' && ch != '*' && ch != '/')
                    throw new ExceptionTree("Waiting sign.");

                value = ch;
                ch = file.Read();  // ' '
                if (ch != ' ')
                    throw new ExceptionTree("Waiting ' '.");

                left = CreateTreeFromFile(file, left);
                right = CreateTreeFromFile(file, right);

                if (value == '+')
                    treeElement = new Add(value, left, right);
                if (value == '-')
                    treeElement = new Subtract(value, left, right);
                if (value == '*')
                    treeElement = new Multiply(value, left, right);
                if (value == '/')
                    treeElement = new Divide(value, left, right);
                ch = file.Read(); // ')' или ' '
                if (ch == ' ')
                    ch = file.Read(); // ')'
                if (ch != ')')
                    throw new ExceptionTree("Waiting ).");
               /* ch = file.Read(); // ' '
                if (ch != ' ')
                    throw new ExceptionTree("Waiting ' '."); */
            }

            else if (ch <= '9' && ch >= '0')
            {
                int number = 0;
                while (ch <= '9' && ch >= '0')
                {
                    number = number * 10 + ch - '0';
                    ch = file.Read();
                }
                if (ch != ' ')
                    throw new ExceptionTree("Waiting ' '.");

                value = number;
                treeElement = new Value(value);
            }
            else
                throw new ExceptionTree("Waiting '(' or number.");
            return treeElement;
        }
        private static Activity HandleBinaryExpression <TLeft, TRight, TResult>(BinaryOperator op, TestExpression left, TestExpression right)
        {
            Activity           we           = null;
            InArgument <TLeft> leftArgument = (InArgument <TLeft>)TestExpression.GetInArgumentFromExpectedNode <TLeft>(left);

            leftArgument.EvaluationOrder = 0;
            InArgument <TRight> rightArgument = (InArgument <TRight>)TestExpression.GetInArgumentFromExpectedNode <TRight>(right);

            rightArgument.EvaluationOrder = 1;

            switch (op)
            {
            case BinaryOperator.Add:
                we = new Add <TLeft, TRight, TResult>()
                {
                    Checked = false,
                    Left    = leftArgument,
                    Right   = rightArgument
                };
                break;

            case BinaryOperator.And:
                we = new And <TLeft, TRight, TResult>()
                {
                    Left  = leftArgument,
                    Right = rightArgument
                };
                break;

            case BinaryOperator.AndAlso:
                we = new AndAlso()
                {
                    Left  = TestExpression.GetWorkflowElementFromExpectedNode <bool>(left),
                    Right = TestExpression.GetWorkflowElementFromExpectedNode <bool>(right)
                };
                break;

            case BinaryOperator.CheckedAdd:
                we = new Add <TLeft, TRight, TResult>()
                {
                    Checked = true,
                    Left    = leftArgument,
                    Right   = rightArgument
                };
                break;

            case BinaryOperator.CheckedMultiply:
                we = new Multiply <TLeft, TRight, TResult>()
                {
                    Checked = true,
                    Left    = leftArgument,
                    Right   = rightArgument
                };
                break;

            case BinaryOperator.CheckedSubtract:
                we = new Subtract <TLeft, TRight, TResult>()
                {
                    Checked = true,
                    Left    = leftArgument,
                    Right   = rightArgument
                };
                break;

            case BinaryOperator.Divide:
                we = new Divide <TLeft, TRight, TResult>()
                {
                    Left  = leftArgument,
                    Right = rightArgument
                };
                break;

            case BinaryOperator.Equal:
                we = new Equal <TLeft, TRight, TResult>()
                {
                    Left  = leftArgument,
                    Right = rightArgument
                };
                break;

            case BinaryOperator.GreaterThan:
                we = new GreaterThan <TLeft, TRight, TResult>()
                {
                    Left  = leftArgument,
                    Right = rightArgument
                };
                break;

            case BinaryOperator.GreaterThanOrEqual:
                we = new GreaterThanOrEqual <TLeft, TRight, TResult>()
                {
                    Left  = leftArgument,
                    Right = rightArgument
                };
                break;

            case BinaryOperator.LessThan:
                we = new LessThan <TLeft, TRight, TResult>()
                {
                    Left  = leftArgument,
                    Right = rightArgument
                };
                break;

            case BinaryOperator.LessThanOrEqual:
                we = new LessThanOrEqual <TLeft, TRight, TResult>()
                {
                    Left  = leftArgument,
                    Right = rightArgument
                };
                break;

            case BinaryOperator.Or:
                we = new Or <TLeft, TRight, TResult>()
                {
                    Left  = leftArgument,
                    Right = rightArgument
                };
                break;

            case BinaryOperator.Multiply:
                we = new Multiply <TLeft, TRight, TResult>()
                {
                    Checked = false,
                    Left    = leftArgument,
                    Right   = rightArgument
                };
                break;

            case BinaryOperator.NotEqual:
                we = new NotEqual <TLeft, TRight, TResult>()
                {
                    Left  = leftArgument,
                    Right = rightArgument
                };
                break;

            case BinaryOperator.OrElse:
                we = new OrElse()
                {
                    Left  = TestExpression.GetWorkflowElementFromExpectedNode <bool>(left),
                    Right = TestExpression.GetWorkflowElementFromExpectedNode <bool>(right)
                };
                break;

            case BinaryOperator.Subtract:
                we = new Subtract <TLeft, TRight, TResult>()
                {
                    Checked = false,
                    Left    = leftArgument,
                    Right   = rightArgument
                };
                break;

            default:
                throw new NotSupportedException(string.Format("Operator: {0} is unsupported", op.ToString()));
            }

            return(we);
        }
 public void TestDivideExpects2()
 {
     var operation = new Divide();
     var result = operation.Operate(16, 8);
     Assert.AreEqual(result, 2);
 }
Example #37
0
    public object CalculateParam(ParleyEnviromentInfo info)
    {
        if (paramaters == null || paramaters.Length == 0)
        {
            return(null);
        }

        if (paramaters.Length == 1 && paramaters[0].StartsWith("\""))
        {
            return(paramaters[0].Substring(1, paramaters[0].Length - 2));
        }

        Stack <float>    values    = new Stack <float>();
        Stack <Operator> operators = new Stack <Operator>();

        bool lastWasTerm  = false;
        bool nextTermFlip = false;

        foreach (string p in paramaters)
        {
            bool term = "+-*/".IndexOf(p) == -1;
            if (term)
            {
                float v = 0;
                if ("0123456789".IndexOf(p.Substring(0, 1)) != -1)
                {
                    v = float.Parse(p);
                }
                else
                {
                    object o = info.GetEnviromentInfo(p);
                    if (o == null)
                    {
                        Debug.LogWarning("Parley could not find the term <" + term + "> from the Enviroment. Substituting 0");
                        v = 0;
                    }
                    else
                    {
                        v = float.Parse(o.ToString());
                    }
                }
                if (nextTermFlip)
                {
                    values.Push(-v);
                }
                else
                {
                    values.Push(v);
                }
                nextTermFlip = false;
                lastWasTerm  = true;
            }
            else
            {
                if (lastWasTerm)
                {
                    Operator o = null;
                    if ("+".Equals(p))
                    {
                        o = new Add();
                    }
                    else if ("-".Equals(p))
                    {
                        o = new Subtract();
                    }
                    else if ("*".Equals(p))
                    {
                        o = new Multiply();
                    }
                    else if ("/".Equals(p))
                    {
                        o = new Divide();
                    }

                    while (operators.Count > 0 && o.weight > operators.Peek().weight)
                    {
                        operators.Pop().Execute(values);
                    }
                    operators.Push(o);
                }
                else
                {
                    // Change sign on next term
                    if ("-".Equals(p))
                    {
                        nextTermFlip = true;
                    }
                }
                lastWasTerm = false;
            }
        }
        while (operators.Count > 0)
        {
            operators.Pop().Execute(values);
        }
        return(values.Pop());
    }
Example #38
0
 public virtual void VisitDivide(Divide n)
 {
 }
Example #39
0
    private IEnumerator OpenDivideAnimate(int _num)
    {
        Divide d        = selectedDivide;
        int    cleared  = PlayerData.Instance.clearedStage[_num - 1];
        float  timer    = 0f;
        float  destTime = 0.4f;

        d.gameObject.SetActive(true);
        divideBtnGroup.SetActive(false);
        for (int i = 0; i < 6; ++i)
        {
            stageBtns[i].anchoredPosition = d.stagePos[i];
            Image  img = stageBtns[i].gameObject.GetComponent <Image>();
            Button btn = stageBtns[i].gameObject.GetComponent <Button>();
            btn.interactable = true;
            if (i == 5)
            {
                if (cleared == 6)
                {
                    img.sprite = bossStageBtnSpr[1];
                }
                else if (cleared == 5)
                {
                    img.sprite = bossStageBtnSpr[2];
                }
                else
                {
                    img.sprite       = bossStageBtnSpr[0];
                    btn.interactable = false;
                }
            }
            else
            {
                if (i < cleared)
                {
                    img.sprite = stageBtnSpr[1];
                }
                else if (i == cleared)
                {
                    img.sprite = stageBtnSpr[2 + i];
                }
                else
                {
                    img.sprite       = stageBtnSpr[0];
                    btn.interactable = false;
                }
            }
        }

        while (true)
        {
            worldSpr.color = Color.Lerp(Color.white, Color.gray, timer / destTime);
            if (timer >= destTime)
            {
                worldSpr.color = Color.gray;
                timer         -= destTime;
                break;
            }
            timer += Time.deltaTime;
            yield return(null);
        }

        destTime = 0.75f;
        Vector2 originPos = cam.transform.position;

        while (true)
        {
            float   t   = camCurve.Evaluate(timer / destTime);
            Vector3 pos = Vector2.Lerp(originPos, d.camCenter, t);
            pos.z = -10f;
            cam.transform.position = pos;
            cam.orthographicSize   = Mathf.Lerp(5f, d.camSize, t);
            if (timer >= destTime)
            {
                pos   = d.camCenter;
                pos.z = -10f;
                cam.transform.position = pos;
                cam.orthographicSize   = d.camSize;
                break;
            }
            timer += Time.deltaTime;
            yield return(null);
        }

        stageBtnGroup.SetActive(true);
        stageSelectedGroup.SetActive(true);
        Vector3[] linePos = new Vector3[6];
        for (int i = 0; i < 6; ++i)
        {
            linePos[i] = d.stagePos[i];
        }
        stageLine.SetPositions(linePos);
        stageLine.gameObject.SetActive(true);
        OnSelectStage(1);
    }
Example #40
0
        public void EvaluateShouldWorkProperly()
        {
            var operand = new Divide();

            Assert.AreEqual(10, operand.Evaluate(20, 2));
        }
Example #41
0
 public virtual void PostVisit(Divide data)
 {
 }