Skip to content
Adarsh Pyarelal edited this page Mar 19, 2018 · 6 revisions

Unit Tests Protocol

We want tests to cover:

  • MITRE & CAGS
  • RAPs
  • At least 1 unit test per rule

Protocol

Rule 1: master branch should always pass!

Rule 2: never work in master!

Rule 3: always work in a short-lived branch!

Once you've implemented a passing test in your branch, make a PR to Keith and Becky. (You can a "assign" it to them in your pull request on github).

Workflow

What to do about overlap?

If someone has fixed something that you have also fixed, you will have to resolve the conflict.

If you don't know how to fix something?

If you need help, reach out to someone who is familiar with ODIN (Mihai, Becky, Gus, etc.)

When should I make a github issue?

Usually you will not need to make an issue. If there is a more serious issue, talk to someone who is familiar with ODIN (e.g. Becky) and they will make a github issue.

Example of writing a unit test:

  • Each Unit Test is a triple.
  • See here for an example!

import CAG._
import TestUtils._

class TestCagP1 extends Test {
  
  { // S1
    val tester = new Tester(p1s1)
  
    val foodInsecurityLevels = newNodeSpec("Food insecurity levels") //fixme: add extra mods
    val conflict = newNodeSpec("conflict")
    val economy = newNodeSpec("economy", newDecrease("collapsing"))
    val cerealProduction = newNodeSpec("cereal production", newDecrease("low"))
    val rainfall = newNodeSpec("rainfall", newDecrease("poor"))
    val copingCapacities = newNodeSpec("coping capacities", newDecrease("exhaustion"))

    behavior of "p1s1"

    failingTest should "have correct edges 1" taggedAs(Somebody) in {
      tester.test(newEdgeSpec(conflict, Causal, foodInsecurityLevels)) should be (successful)
    }
    failingTest should "have correct edges 2" taggedAs(Somebody) in {
      tester.test(newEdgeSpec(economy, Causal, foodInsecurityLevels)) should be (successful)
    }
    failingTest should "have correct edges 3" taggedAs(Somebody) in {
      tester.test(newEdgeSpec(cerealProduction, Causal, foodInsecurityLevels)) should be (successful)
    }
    failingTest should "have correct edges 4" taggedAs(Somebody) in {
      tester.test(newEdgeSpec(rainfall, Causal, foodInsecurityLevels)) should be (successful)
    }
    failingTest should "have correct edges 5" taggedAs(Somebody) in {
      tester.test(newEdgeSpec(copingCapacities, Causal, foodInsecurityLevels)) should be (successful)
    }
  }
}

Q: What if the test fails? What do you do to understand what is wrong?

Using the visualizer will help you! How to run the visualizer:

  1. Go to the console and navigate to the /eidos main dir.

  2. Run sbt webapp/run from the eidos main directory. (E.g. YourComputer:eidos user$ sbt webapp/run)

  3. Go to http://localhost:9000/ in your browser

  4. Enter your sentence into the box and hit "submit!" The first time it might be a little slow, as it is loading all of the parsers, taggers, etc. If it doesn't work, you may need to check how much memory you are allocating to sbt (check sbt_opts).

Look at the BRAT visualization to see what entities are captured, what dependencies are present, etc. Compare this with what you are trying to capture. Is it not finding the entity? Is the grammar missing a trigger? Etc.

  1. Once you fix a rule, you can see if the webapp has refreshed if you see "compiling...". There is another way to do this, that Becky will add here where you can force it to refresh :)

AND/OR

Using the EidosShell will help you see what is and isn't being captured by the grammar. You can run this by running sbt run in the eidos home dir, and selecting the EidosShell option.