package com.bs.mes.schedule.strategy;

import com.ximai.mes.pro.schedule.Equipment;
import com.ximai.mes.pro.schedule.IOperationTimeCalculator;
import com.ximai.mes.pro.schedule.Job;
import com.ximai.mes.pro.schedule.TaskSchedulingContext;
import com.ximai.mes.pro.schedule.strategy.EvaluateEquipmentFunction;
import org.junit.Assert;
import org.junit.Test;

import java.time.Duration;
import java.util.ArrayList;
import java.util.List;

public class EvaluateEquipmentFunctionTest {
    @Test public void evaluate(){
        EvaluateEquipmentFunction evaluateEquipmentFunction = new EvaluateEquipmentFunction();
        TaskSchedulingContext context = new TaskSchedulingContext();
        IOperationTimeCalculator.OperationTimePlan operationTimePlan = new IOperationTimeCalculator.OperationTimePlan();
        List<IOperationTimeCalculator.OperationTimePlanItem> operationTimePlanItemList = new ArrayList<IOperationTimeCalculator.OperationTimePlanItem>();
        operationTimePlan.setPlan(operationTimePlanItemList);
        operationTimePlan.setScheduledSuccess(true);
        Job job = new Job("1", Duration.ofMinutes(12));
        job.setProducedDeliveryTime(Duration.ofMinutes(3000));
        context.setJob(job);
        operationTimePlanItemList.add(new IOperationTimeCalculator.OperationTimePlanItem(){{
            setStartedTime(Duration.ofMinutes(2888));
            setEndedTime(Duration.ofMinutes(2898));
            setShiftType("白班");
        }});
        Equipment equipment = new Equipment();
        context.setEquipment(equipment);
        Equipment.EquipmentFunction equipmentFunction = new Equipment.EquipmentFunction();
        equipmentFunction.setSacmForBuckleUp("Y");
        equipmentFunction.setSacmForOrgan("Y");
        equipmentFunction.setSacmForEdgeOpening("N");
        equipment.setEquipmentFunction(equipmentFunction);
        double rst = evaluateEquipmentFunction.evaluate(context, operationTimePlan, null);
        Assert.assertEquals(8, rst, Double.valueOf(0.001));

        equipmentFunction.setSacmForEdgeOpening("Y");
        equipmentFunction.setSacmForSlitting("Y");
        equipmentFunction.setSacmForMolarTooth("Y");
        equipmentFunction.setSacmForThermalComposite("Y");
        equipmentFunction.setSacmForPasteComposite("Y");
        equipmentFunction.setSacmForThermalCutting("Y");
        equipmentFunction.setSacmForThermalSelfFusion("Y");
        equipmentFunction.setSacmForCreasing("Y");
        equipmentFunction.setSacmForLabeling("Y");
        rst = evaluateEquipmentFunction.evaluate(context, operationTimePlan, null);
        Assert.assertEquals(0, rst, Double.valueOf(0.001));


    }
}
