/**
 * evaluateExpressionLite 测试 — 基于 RAW 数据集
 *
 * 使用方式：
 *   npx jest tests/eva.test.ts
 */
import { evaluateExpressionLite } from '../src/views/system/algorithm/utils/evaluator';
import { DEFAULT_DISPLAY_MAP, DEFAULT_OPERAND_SET } from '../src/views/system/algorithm/utils/config';

const RAW = [
  {
    name: '压差测试陕西益东矿业有限责任公司',
    expr: 'sourcePressureChange>80',
    reasons: ['sourcePressureChange'],
  },
  {
    name: '闭内火灾测试陕西益东矿业有限责任公司',
    expr: '((coRzl>20 && coRzl<=50) ||  (0.5*coAvg<coZf && coZf<=coAvg)  || (coVal>10 && coVal<=50) || (temperatureDifference>=2 && temperatureDifference<=4)) && co2Val<0.5',
    reasons: ['coVal', 'co2Val'],
  },
  {
    name: '闭外火灾测试陕西益东矿业有限责任公司',
    expr: '(temperatureDifferenceOut>10 && temperatureOut>=30) || (ch4ValOut>=1.5 && ch4ValOut<2) || coValOut>=24 || c2h2ValOut>0',
    reasons: ['coValOut'],
  },
  {
    name: '压差测试陕西益东矿业有限责任公司',
    expr: 'sourcePressureChange>80',
    reasons: ['sourcePressureChange'],
  },
  {
    name: '闭内火灾测试陕西益东矿业有限责任公司',
    expr: '((coRzl>50 && coRzl<=100) ||  (coAvg<coZf && coZf<=2*coAvg)  || (coVal>=50 && coVal<=100) || (temperatureDifference>4 && temperatureDifference<=10)) && co2Val<0.5  || (c2h4Val>0 && c2h2Val==0)',
    reasons: ['c2h2Val', 'co2Val', 'coRzl'],
  },
  {
    name: '闭外火灾测试陕西益东矿业有限责任公司',
    expr: 'temperatureDifferenceOut<2 || (ch4ValOut>0 && ch4ValOut<0.5) || (coValOut>=0 && coValOut<5) || o2ValOut < 20',
    reasons: ['o2ValOut', 'coValOut'],
  },
  {
    name: '压差测试陕西益东矿业有限责任公司',
    expr: 'sourcePressureChange>80',
    reasons: ['sourcePressureChange'],
  },
  {
    name: '闭内火灾测试陕西益东矿业有限责任公司',
    expr: '(((coRzl<=20 || coZf<=0.5*coAvg) && coVal<=10)||o2Val<=5 ) && temperatureDifference<2 && co2Val<0.5',
    reasons: ['coVal', 'coZf', 'coRzl'],
  },
  {
    name: '闭外火灾测试陕西益东矿业有限责任公司',
    expr: '(temperatureDifferenceOut>10 && temperatureOut>=30) || (ch4ValOut>=1.5 && ch4ValOut<2) || coValOut>=24 || c2h2ValOut>0',
    reasons: ['coValOut'],
  },
  {
    name: '压差测试陕西益东矿业有限责任公司',
    expr: 'sourcePressureChange>80',
    reasons: ['sourcePressureChange'],
  },
  {
    name: '闭内火灾测试陕西益东矿业有限责任公司',
    expr: '((coRzl>20 && coRzl<=50) ||  (0.5*coAvg<coZf && coZf<=coAvg)  || (coVal>10 && coVal<=50) || (temperatureDifference>=2 && temperatureDifference<=4)) && co2Val<0.5',
    reasons: ['coVal', 'co2Val'],
  },
  {
    name: '闭外火灾测试陕西益东矿业有限责任公司',
    expr: '(temperatureDifferenceOut>4 && temperatureDifferenceOut<=10 && temperatureOut>=26) || (ch4ValOut>=1 && ch4ValOut<1.5) || (coValOut>=10 && coValOut<24)  || (c2h4ValOut>0 && c2h2ValOut==0)',
    reasons: ['c2h2ValOut', 'coValOut'],
  },
  {
    name: '压差测试陕西益东矿业有限责任公司',
    expr: 'sourcePressureChange>80',
    reasons: ['sourcePressureChange'],
  },
  {
    name: '闭内火灾测试陕西益东矿业有限责任公司',
    expr: '((coRzl>20 && coRzl<=50) ||  (0.5*coAvg<coZf && coZf<=coAvg)  || (coVal>10 && coVal<=50) || (temperatureDifference>=2 && temperatureDifference<=4)) && co2Val<0.5',
    reasons: ['coVal', 'co2Val', 'coRzl'],
  },
  {
    name: '闭外火灾测试陕西益东矿业有限责任公司',
    expr: '(temperatureDifferenceOut>=2 && temperatureDifferenceOut<=4) || (ch4ValOut>=0.5 && ch4ValOut <=1) || (coValOut>=5 && coValOut<10)',
    reasons: ['coValOut'],
  },
  {
    name: '闭外火灾测试红柳林煤矿',
    expr: 'temperatureDifferenceOut<2 || (ch4ValOut>0 && ch4ValOut<0.5) || (coValOut>=0 && coValOut<5) || o2ValOut < 20',
    reasons: ['coValOut'],
  },
  {
    name: '闭外火灾测试红柳林煤矿',
    expr: 'temperatureDifferenceOut<2 || (ch4ValOut>0 && ch4ValOut<0.5) || (coValOut>=0 && coValOut<5) || o2ValOut < 20',
    reasons: ['coValOut'],
  },
  {
    name: '闭外火灾测试红柳林煤矿',
    expr: 'temperatureDifferenceOut<2 || (ch4ValOut>0 && ch4ValOut<0.5) || (coValOut>=0 && coValOut<5) || o2ValOut < 20',
    reasons: ['coValOut'],
  },
  {
    name: '闭外火灾测试红柳林煤矿',
    expr: 'temperatureDifferenceOut<2 || (ch4ValOut>0 && ch4ValOut<0.5) || (coValOut>=0 && coValOut<5) || o2ValOut < 20',
    reasons: ['coValOut'],
  },
  {
    name: '闭外火灾测试红柳林煤矿',
    expr: 'temperatureDifferenceOut<2 || (ch4ValOut>0 && ch4ValOut<0.5) || (coValOut>=0 && coValOut<5) || o2ValOut < 20',
    reasons: ['coValOut'],
  },
  {
    name: '闭外火灾测试红柳林煤矿',
    expr: 'temperatureDifferenceOut<2 || (ch4ValOut>0 && ch4ValOut<0.5) || (coValOut>=0 && coValOut<5) || o2ValOut < 20',
    reasons: ['coValOut'],
  },
  {
    name: '闭外火灾测试红柳林煤矿',
    expr: 'temperatureDifferenceOut<2 || (ch4ValOut>0 && ch4ValOut<0.5) || (coValOut>=0 && coValOut<5) || o2ValOut < 20',
    reasons: ['coValOut'],
  },
];

describe('evaluateExpressionLite', () => {
  RAW.forEach(({ name, expr, reasons }) => {
    const result = evaluateExpressionLite(expr, reasons, DEFAULT_OPERAND_SET, DEFAULT_DISPLAY_MAP);

    // 验证每个 reason 关键字都在 summary 中被提及
    it(name, () => {
      console.log(`[${name}]预警原因：${reasons}`);
      console.log(result);
      expect(result.length).toBeGreaterThanOrEqual(0);

      // DEFAULT_OPERAND_SET.
    });
  });
});
