package com.bs.mes.schedule.strategy;

import com.ximai.mes.pro.schedule.strategy.EvaluateEquipmentChangeOver;
import org.junit.Assert;
import org.junit.Test;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

public class EvaluateEquipmentChangeOverTest {

    @Test public void calculateScore() throws Exception {
        EvaluateEquipmentChangeOver evaluateEquipmentChangeOver = new EvaluateEquipmentChangeOver();
        Method methods = EvaluateEquipmentChangeOver.class.getDeclaredMethod("calculateScore", Map.class, Map.class, Map.class);
        methods.setAccessible(true);
        Map<String, Integer> setupRuleMap = new HashMap<String, Integer>();//当前任务换型规则
        setupRuleMap.put("tool", 1);
        setupRuleMap.put("sheet_width", 2);
        setupRuleMap.put("product_standard", 3);
        Map<String, Object> setupRuleValsCur = new HashMap<String, Object>();//当前任务工单换型属性值
        setupRuleValsCur.put("tool", "1");
        setupRuleValsCur.put("sheet_width", "2");
        setupRuleValsCur.put("product_standard", "3");
        Map<String, Object> setupRuleValsPre = new HashMap<String, Object>();//上个任务工单换型属性值
        setupRuleValsPre.put("tool", "1.1");
        setupRuleValsPre.put("sheet_width", "2");
        setupRuleValsPre.put("product_standard", "3");
        double rst = (double)methods.invoke(evaluateEquipmentChangeOver, setupRuleMap, setupRuleValsCur, setupRuleValsPre);
        Assert.assertEquals(5.0/15*10, rst, 0.1);

        //优先级全为1的情况
        setupRuleMap.clear();
        setupRuleValsCur.clear();
        setupRuleValsPre.clear();

        setupRuleMap.put("tool", 1);
        setupRuleMap.put("sheet_width", 1);
        setupRuleMap.put("product_standard", 1);
        setupRuleMap.put("pro_con_color", 1);
        setupRuleMap.put("inlay", 1);
        setupRuleMap.put("product_width", 1);

        setupRuleValsCur.put("tool", "1");
        setupRuleValsCur.put("sheet_width", "2");
        setupRuleValsCur.put("product_standard", "3");
        setupRuleValsCur.put("pro_con_color", "4");
        setupRuleValsCur.put("inlay", "5.1");
        setupRuleValsCur.put("product_width", "6");

        setupRuleValsPre.put("tool", "1.1");
        setupRuleValsPre.put("sheet_width", "2");
        setupRuleValsPre.put("product_standard", "3");
        setupRuleValsPre.put("pro_con_color", "4");
        setupRuleValsPre.put("inlay", "5.2");
        setupRuleValsPre.put("product_width", "6");
        rst = (double)methods.invoke(evaluateEquipmentChangeOver, setupRuleMap, setupRuleValsCur, setupRuleValsPre);
        Assert.assertEquals(16.0/30*10, rst, 0.1);

    }

}
