@Test
 public void testXPDFSampleParametersXPDFSampleParameters() {
   XPDFSampleParameters copy = new XPDFSampleParameters(sample);
   assertEquals(sample.getName(), copy.getName());
   assertEquals(sample.getPhases(), copy.getPhases());
   assertEquals(sample.getPhaseWeightings(), copy.getPhaseWeightings());
   assertEquals(sample.isSample(), copy.isSample());
   assertEquals(sample.getComposition(), copy.getComposition());
   assertEquals(sample.getDensity(), copy.getDensity(), 1e-3);
   assertEquals(sample.getPackingFraction(), copy.getPackingFraction(), 1e-3);
   assertEquals(sample.getShapeName(), copy.getShapeName());
 }
 @Test
 public void testSetGetPhases() {
   List<XPDFPhase> newPhases = new ArrayList<XPDFPhase>();
   newPhases.add(SampleTestData.createTestPhase("ilmenite"));
   sample.setPhases(newPhases);
   assertEquals(newPhases, sample.getPhases());
 }
 @Test
 public void testSetGetPhaseWeighting() {
   XPDFPhase firstPhase = sample.getPhases().get(0);
   double newWeight = 0.9;
   sample.setPhaseWeighting(firstPhase, newWeight);
   assertEquals(
       "Phase weighting not set/got correctly",
       newWeight,
       sample.getPhaseWeighting(firstPhase),
       1e-3);
 }
 @Test
 public void testAddPhaseXPDFPhaseDouble() {
   XPDFPhase rutile = SampleTestData.createTestPhase("rutile");
   double rutileWeight = 0.1;
   sample.addPhase(rutile, rutileWeight);
   assertTrue("New weighted phase not successfully added", sample.getPhases().contains(rutile));
   assertEquals(
       "New phase weighting not successfully retrieved",
       sample.getPhaseWeighting(rutile),
       rutileWeight,
       1e-3);
 }
 private void testBasicFieldCreation() {
   assertTrue("XPDFSampleParameters was not successfully created", sample != null);
   assertTrue("Phases list not successfully created", sample.getPhases() != null);
   assertTrue("Fractions list not successfully created", sample.getPhaseWeightings() != null);
 }
  @Test
  public void testWriteNX() {

    String filename = "/tmp/sample.nxs";
    NexusFileBuilder builder = new DefaultNexusFileBuilder(filename);
    NXsample nxample = sample.getNXsample(builder);

    int nCompo = sample.getPhases().size();

    assertEquals("NX name incorrect", sample.getName(), nxample.getNameScalar());
    assertEquals(
        "NX description incorrect",
        sample.getName() + ", " + sample.getComposition() + ", " + sample.getShapeName(),
        nxample.getDescriptionScalar());
    assertEquals(
        "NX component names incorrect",
        DatasetFactory.createFromList(
            sample.getPhases().stream().map(a -> a.getName()).collect(Collectors.toList())),
        nxample.getComponent());
    assertEquals(
        "NX component formulae incorrect",
        DatasetFactory.createFromObject(
            sample
                .getPhases()
                .stream()
                .map(a -> a.getComposition().getHallNotation(false))
                .collect(Collectors.toList()),
            nCompo,
            1),
        nxample.getChemical_formula());
    assertEquals(
        "NX formula weight incorrect",
        DatasetFactory.createFromList(
            sample
                .getPhases()
                .stream()
                .map(a -> a.getComposition().getFormulaMass())
                .collect(Collectors.toList())),
        nxample.getDataset("chemical_formula_weight"));
    // unit cell parameters...
    assertEquals(
        "NX unit cell volume incorrect",
        DatasetFactory.createFromList(
            sample
                .getPhases()
                .stream()
                .map(a -> a.getUnitCellVolume())
                .collect(Collectors.toList())),
        nxample.getUnit_cell_volume());
    assertEquals(
        "NX unit cell class incorrect",
        DatasetFactory.createFromList(
            sample
                .getPhases()
                .stream()
                .map(a -> a.getCrystalSystem().getName())
                .collect(Collectors.toList())),
        nxample.getUnit_cell_class());
    assertEquals(
        "NX unit cell space group incorrect",
        DatasetFactory.createFromList(
            sample
                .getPhases()
                .stream()
                .map(a -> a.getSpaceGroup().getNumber() + ": " + a.getSpaceGroup().getName())
                .collect(Collectors.toList())),
        nxample.getUnit_cell_group());
    assertEquals(
        "NX theoretical densities incorrect",
        DatasetFactory.createFromList(
            sample.getPhases().stream().map(a -> a.getDensity()).collect(Collectors.toList())),
        nxample.getDataset("theoretical_density"));
  }
 @Test
 public void testAddPhaseXPDFPhase() {
   XPDFPhase rutile = SampleTestData.createTestPhase("rutile");
   sample.addPhase(rutile);
   assertTrue("New phase not successfully added", sample.getPhases().contains(rutile));
 }
 @Test
 public void testClearPhases() {
   sample.clearPhases();
   assertTrue("XPDFSampleParameters phase list not cleared", sample.getPhases().isEmpty());
 }