time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

domain.js (1435B)


      1 import { REArgumentError } from "../errors/messages.js";
      2 class BaseDomain {
      3 }
      4 export class NumericRangeDomain extends BaseDomain {
      5     constructor(min, max) {
      6         super();
      7         this.min = min;
      8         this.max = max;
      9         this.type = "NumericRange";
     10     }
     11     toString() {
     12         return `Number.rangeDomain({ min: ${this.min}, max: ${this.max} })`;
     13     }
     14     includes(value) {
     15         return (value.type === "Number" &&
     16             value.value >= this.min &&
     17             value.value <= this.max);
     18     }
     19     isEqual(other) {
     20         return this.min === other.min && this.max === other.max;
     21     }
     22 }
     23 export function annotationToDomain(value) {
     24     if (value.type === "Domain") {
     25         return value.value;
     26     }
     27     if (value.type !== "Array") {
     28         throw new REArgumentError("Only array domains are supported");
     29     }
     30     if (value.value.length !== 2) {
     31         throw new REArgumentError("Expected two-value array");
     32     }
     33     const [min, max] = value.value;
     34     if (min.type !== "Number") {
     35         throw new REArgumentError("Min value is not a number");
     36     }
     37     if (max.type !== "Number") {
     38         throw new REArgumentError("Max value is not a number");
     39     }
     40     if (min.value >= max.value) {
     41         throw new REArgumentError(`The range minimum (${min.value}) must be lower than the range maximum (${max.value})`);
     42     }
     43     return new NumericRangeDomain(min.value, max.value);
     44 }
     45 //# sourceMappingURL=domain.js.map