{
  "format": 1,
  "method": "hanawalt-xrd-search-match",
  "version": "0.1.0",
  "interface": "search_match(observed, references, tolerance) -> ranked list of records with phase, score, observed_coverage, reference_coverage, and matched. A list of peaks contains [d in angstroms, positive intensity] pairs. references maps phase identifiers to peak lists. The position tolerance is absolute and in angstroms. Count each measured and reference line at most once. Compare the returned order and labels exactly and floats within tol.",
  "cases": [
    {
      "name": "observed prime gates the phase",
      "operation": "search_match",
      "args": [
        [
          [
            4,
            100
          ],
          [
            3,
            60
          ],
          [
            2,
            40
          ],
          [
            1,
            20
          ]
        ],
        {
          "correct": [
            [
              4,
              100
            ],
            [
              3,
              60
            ],
            [
              2,
              40
            ],
            [
              1,
              20
            ]
          ],
          "secondary": [
            [
              3,
              100
            ],
            [
              2,
              60
            ],
            [
              1,
              40
            ]
          ]
        },
        0.01
      ],
      "expected": [
        {
          "phase": "correct",
          "score": 1.0,
          "observed_coverage": 1.0,
          "reference_coverage": 1.0,
          "matched": 4
        }
      ],
      "tol": 1e-12
    },
    {
      "name": "close anchors cannot reuse the same measured peak",
      "operation": "search_match",
      "args": [
        [
          [
            4,
            100
          ],
          [
            3.02,
            40
          ],
          [
            1,
            10
          ]
        ],
        {
          "duplicate-hit": [
            [
              4,
              100
            ],
            [
              3,
              70
            ],
            [
              3.04,
              50
            ]
          ]
        },
        0.025
      ],
      "expected": [],
      "tol": 1e-12
    },
    {
      "name": "confirmation cannot reuse the prime",
      "operation": "search_match",
      "args": [
        [
          [
            4,
            100
          ],
          [
            3,
            60
          ],
          [
            2,
            40
          ],
          [
            1,
            20
          ]
        ],
        {
          "overlap": [
            [
              4,
              100
            ],
            [
              3,
              60
            ],
            [
              2,
              40
            ],
            [
              4.03125,
              20
            ]
          ]
        },
        0.0625
      ],
      "expected": [
        {
          "phase": "overlap",
          "score": 0.9090909090909091,
          "observed_coverage": 0.9090909090909091,
          "reference_coverage": 0.9090909090909091,
          "matched": 3
        }
      ],
      "tol": 1e-12
    },
    {
      "name": "the spacing tolerance includes exact binary boundaries",
      "operation": "search_match",
      "args": [
        [
          [
            4,
            100
          ],
          [
            3,
            60
          ],
          [
            2,
            40
          ],
          [
            1,
            20
          ]
        ],
        {
          "boundary": [
            [
              4.125,
              100
            ],
            [
              2.875,
              60
            ],
            [
              2.125,
              40
            ],
            [
              0.875,
              20
            ]
          ]
        },
        0.125
      ],
      "expected": [
        {
          "phase": "boundary",
          "score": 1.0,
          "observed_coverage": 1.0,
          "reference_coverage": 1.0,
          "matched": 4
        }
      ],
      "tol": 1e-12
    },
    {
      "name": "both measured and reference intensities matter",
      "operation": "search_match",
      "args": [
        [
          [
            4,
            100
          ],
          [
            3,
            70
          ],
          [
            3.4,
            60
          ],
          [
            2,
            50
          ],
          [
            1,
            10
          ]
        ],
        {
          "closer": [
            [
              4.001,
              100
            ],
            [
              3,
              70
            ],
            [
              2,
              50
            ],
            [
              1,
              10
            ]
          ],
          "partial": [
            [
              4,
              100
            ],
            [
              3,
              70
            ],
            [
              2,
              50
            ],
            [
              1.2,
              40
            ]
          ]
        },
        0.01
      ],
      "expected": [
        {
          "phase": "closer",
          "score": 0.8846153846153845,
          "observed_coverage": 0.793103448275862,
          "reference_coverage": 1.0,
          "matched": 4
        },
        {
          "phase": "partial",
          "score": 0.8,
          "observed_coverage": 0.7586206896551725,
          "reference_coverage": 0.8461538461538461,
          "matched": 3
        }
      ],
      "tol": 1e-12
    },
    {
      "name": "confirmation uses the first eligible line in spacing order",
      "operation": "search_match",
      "args": [
        [
          [
            4,
            100
          ],
          [
            3,
            70
          ],
          [
            2,
            60
          ],
          [
            1,
            8
          ],
          [
            1.03,
            24
          ]
        ],
        {
          "candidate": [
            [
              4,
              100
            ],
            [
              3,
              70
            ],
            [
              2,
              60
            ],
            [
              1.025,
              20
            ]
          ]
        },
        0.03
      ],
      "expected": [
        {
          "phase": "candidate",
          "score": 0.9520000000000001,
          "observed_coverage": 0.9083969465648855,
          "reference_coverage": 1.0,
          "matched": 4
        }
      ],
      "tol": 1e-12
    },
    {
      "name": "gain-independent ordering and phase-id tie break",
      "operation": "search_match",
      "args": [
        [
          [
            4,
            100
          ],
          [
            3,
            60
          ],
          [
            2,
            40
          ],
          [
            1,
            20
          ]
        ],
        {
          "z": [
            [
              4,
              100
            ],
            [
              3,
              60
            ],
            [
              2,
              40
            ],
            [
              1,
              20
            ]
          ],
          "a": [
            [
              4,
              1000
            ],
            [
              3,
              600
            ],
            [
              2,
              400
            ],
            [
              1,
              200
            ]
          ]
        },
        0.01
      ],
      "expected": [
        {
          "phase": "a",
          "score": 1.0,
          "observed_coverage": 1.0,
          "reference_coverage": 1.0,
          "matched": 4
        },
        {
          "phase": "z",
          "score": 1.0,
          "observed_coverage": 1.0,
          "reference_coverage": 1.0,
          "matched": 4
        }
      ],
      "tol": 1e-12
    },
    {
      "name": "equal intensity uses the larger prime spacing",
      "operation": "search_match",
      "args": [
        [
          [
            3,
            100
          ],
          [
            4,
            100
          ],
          [
            2,
            20
          ]
        ],
        {
          "prime-four": [
            [
              4,
              100
            ],
            [
              3,
              25
            ],
            [
              2,
              20
            ]
          ]
        },
        0.01
      ],
      "expected": [
        {
          "phase": "prime-four",
          "score": 1.0,
          "observed_coverage": 1.0,
          "reference_coverage": 1.0,
          "matched": 3
        }
      ],
      "tol": 1e-12
    },
    {
      "name": "no candidates with only two measured lines",
      "operation": "search_match",
      "args": [
        [
          [
            4,
            100
          ],
          [
            3,
            60
          ]
        ],
        {
          "candidate": [
            [
              4,
              100
            ],
            [
              3,
              60
            ],
            [
              2,
              40
            ],
            [
              1,
              20
            ]
          ]
        },
        0.01
      ],
      "expected": [],
      "tol": 1e-12
    }
  ]
}
