// Path: src/test/java/de/imi/marw/viper/test/util/TestUtil.java
// public class TestUtil {
// 
//     public static String getResourceFile(String fileName) {
//         // see https://stackoverflow.com/questions/24499692/access-resources-in-unit-tests
//         try {
//             URI uri = TestUtil.class.getClassLoader().getResource(fileName).toURI();
//             return uri.getRawPath();
//         } catch (URISyntaxException ex) {
//             Logger.getLogger(TestUtil.class.getName()).log(Level.SEVERE, null, ex);
//         }
//         return null;
//     }
// 
// }
// 
// Path: src/main/java/de/imi/marw/viper/visualization/SamplePartners.java
// public class SamplePartners {
// 
//     private static final List<String> EMPTY_LIST = Collections.unmodifiableList(new ArrayList<>());
// 
//     private final Map<String, List<String>> samplePartnerMap;
// 
//     public SamplePartners() {
//         this.samplePartnerMap = new HashMap<>();
//     }
// 
//     private SamplePartners(Map<String, List<String>> samplePartnerMap) {
// 
//         this.samplePartnerMap = samplePartnerMap;
//     }
// 
//     public Map<String, List<String>> getMap() {
//         return Collections.unmodifiableMap(this.samplePartnerMap);
//     }
// 
//     public List<String> getPartners(String sample) {
// 
//         if (!this.samplePartnerMap.containsKey(sample)) {
//             return EMPTY_LIST;
//         }
// 
//         return samplePartnerMap.get(sample);
// 
//     }
// 
//     private static Map<String, List<String>> getPartnersFromLines(List<List<String>> lines) {
// 
//         Map<String, List<String>> partnerMap = new HashMap<>();
// 
//         for (List<String> line : lines) {
// 
//             for (String sample : line) {
// 
//                 if (!partnerMap.containsKey(sample)) {
//                     partnerMap.put(sample, new ArrayList<>());
//                 }
// 
//                 List<String> existingSamples = partnerMap.get(sample);
// 
//                 for (String otherSample : line) {
// 
//                     if (!otherSample.equals(sample) && !existingSamples.contains(otherSample)) {
//                         existingSamples.add(otherSample);
//                     }
// 
//                 }
//             }
// 
//         }
// 
//         return partnerMap;
//     }
// 
//     public static SamplePartners loadFromCsv(String fileName, char delimiter) {
// 
//         CSVFormat csvFormat = CSVFormat.RFC4180
//                 .withDelimiter(delimiter);
// 
//         try (Reader rd = new FileReader(new File(fileName))) {
// 
//             Iterable<CSVRecord> records = csvFormat.parse(rd);
// 
//             List<List<String>> lines = StreamSupport.stream(records.spliterator(), false)
//                     .map(record -> StreamSupport.stream(record.spliterator(), false).collect(Collectors.toList()))
//                     .collect(Collectors.toList());
// 
//             Map<String, List<String>> samplePartnerMap = getPartnersFromLines(lines);
// 
//             return new SamplePartners(samplePartnerMap);
// 
//         } catch (FileNotFoundException ex) {
//             System.err.println("[WARNING] File " + fileName + " not found, partnering is ignored.");
//             return new SamplePartners();
//         } catch (IOException ex) {
//             System.err.println("[ERROR] Error reading file " + fileName + ":");
//             Logger.getLogger(SamplePartners.class.getName()).log(Level.SEVERE, null, ex);
//             return new SamplePartners();
//         }
// 
//     }
// }


import de.imi.marw.viper.test.util.TestUtil;
import de.imi.marw.viper.visualization.SamplePartners;
import java.io.IOException;
import java.util.Arrays;
import org.junit.Assert;
import org.junit.Test;
import static org.junit.Assert.*;
/* Copyright (c) 2017 Marius Wöste
 *
 * This file is part of VIPER.
 *
 * VIPER is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * VIPER is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with VIPER.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
package de.imi.marw.viper.test.visualization;



/**
 *
 * @author marius
 */
public class SamplePartnerTest {

    @Test
    public void emptyPartnersTest() throws IOException {

        SamplePartners partners = SamplePartners.loadFromCsv(TestUtil.getResourceFile("partners/empty.csv"), '\t');

        Assert.assertEquals(0, partners.getPartners("BATMAN").size());

    }

    @Test
    public void nonExistentFileTest() throws IOException {

        SamplePartners partners = SamplePartners.loadFromCsv("this-file-better-be-non-existent.csv", ',');

// Path: src/test/java/de/imi/marw/viper/test/util/TestUtil.java
// public class TestUtil {
// 
//     public static String getResourceFile(String fileName) {
//         // see https://stackoverflow.com/questions/24499692/access-resources-in-unit-tests
//         try {
//             URI uri = TestUtil.class.getClassLoader().getResource(fileName).toURI();
//             return uri.getRawPath();
//         } catch (URISyntaxException ex) {
//             Logger.getLogger(TestUtil.class.getName()).log(Level.SEVERE, null, ex);
//         }
//         return null;
//     }
// 
// }
// 
// Path: src/main/java/de/imi/marw/viper/visualization/SamplePartners.java
// public class SamplePartners {
// 
//     private static final List<String> EMPTY_LIST = Collections.unmodifiableList(new ArrayList<>());
// 
//     private final Map<String, List<String>> samplePartnerMap;
// 
//     public SamplePartners() {
//         this.samplePartnerMap = new HashMap<>();
//     }
// 
//     private SamplePartners(Map<String, List<String>> samplePartnerMap) {
// 
//         this.samplePartnerMap = samplePartnerMap;
//     }
// 
//     public Map<String, List<String>> getMap() {
//         return Collections.unmodifiableMap(this.samplePartnerMap);
//     }
// 
//     public List<String> getPartners(String sample) {
// 
//         if (!this.samplePartnerMap.containsKey(sample)) {
//             return EMPTY_LIST;
//         }
// 
//         return samplePartnerMap.get(sample);
// 
//     }
// 
//     private static Map<String, List<String>> getPartnersFromLines(List<List<String>> lines) {
// 
//         Map<String, List<String>> partnerMap = new HashMap<>();
// 
//         for (List<String> line : lines) {
// 
//             for (String sample : line) {
// 
//                 if (!partnerMap.containsKey(sample)) {
//                     partnerMap.put(sample, new ArrayList<>());
//                 }
// 
//                 List<String> existingSamples = partnerMap.get(sample);
// 
//                 for (String otherSample : line) {
// 
//                     if (!otherSample.equals(sample) && !existingSamples.contains(otherSample)) {
//                         existingSamples.add(otherSample);
//                     }
// 
//                 }
//             }
// 
//         }
// 
//         return partnerMap;
//     }
// 
//     public static SamplePartners loadFromCsv(String fileName, char delimiter) {
// 
//         CSVFormat csvFormat = CSVFormat.RFC4180
//                 .withDelimiter(delimiter);
// 
//         try (Reader rd = new FileReader(new File(fileName))) {
// 
//             Iterable<CSVRecord> records = csvFormat.parse(rd);
// 
//             List<List<String>> lines = StreamSupport.stream(records.spliterator(), false)
//                     .map(record -> StreamSupport.stream(record.spliterator(), false).collect(Collectors.toList()))
//                     .collect(Collectors.toList());
// 
//             Map<String, List<String>> samplePartnerMap = getPartnersFromLines(lines);
// 
//             return new SamplePartners(samplePartnerMap);
// 
//         } catch (FileNotFoundException ex) {
//             System.err.println("[WARNING] File " + fileName + " not found, partnering is ignored.");
//             return new SamplePartners();
//         } catch (IOException ex) {
//             System.err.println("[ERROR] Error reading file " + fileName + ":");
//             Logger.getLogger(SamplePartners.class.getName()).log(Level.SEVERE, null, ex);
//             return new SamplePartners();
//         }
// 
//     }
// }


// Path: src/test/java/de/imi/marw/viper/test/visualization/SamplePartnerTest.java
import de.imi.marw.viper.test.util.TestUtil;
import de.imi.marw.viper.visualization.SamplePartners;
import java.io.IOException;
import java.util.Arrays;
import org.junit.Assert;
import org.junit.Test;
import static org.junit.Assert.*;

/* Copyright (c) 2017 Marius Wöste
 *
 * This file is part of VIPER.
 *
 * VIPER is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * VIPER is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with VIPER.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
package de.imi.marw.viper.test.visualization;



/**
 *
 * @author marius
 */
public class SamplePartnerTest {

    @Test
    public void emptyPartnersTest() throws IOException {

        SamplePartners partners = SamplePartners.loadFromCsv(TestUtil.getResourceFile("partners/empty.csv"), '\t');

        Assert.assertEquals(0, partners.getPartners("BATMAN").size());

    }

    @Test
    public void nonExistentFileTest() throws IOException {

        SamplePartners partners = SamplePartners.loadFromCsv("this-file-better-be-non-existent.csv", ',');

        assertEquals(0, partners.getPartners("Grinch").size());