Package de.timefinder.algo.graph

Source Code of de.timefinder.algo.graph.BipartiteWeightedGraphTest

/*
* This file is part of the TimeFinder project.
* Visit http://www.timefinder.de for more information.
* Copyright 2008 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*       http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.timefinder.algo.graph;

import de.timefinder.algo.graph.BipartiteWeightedGraph;
import java.util.Collection;
import java.util.Iterator;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;

/**
* @author Peter Karich, peat_hal 'at' users 'dot' sourceforge 'dot' net
*/
public class BipartiteWeightedGraphTest {

    private BipartiteWeightedGraph graph;

    @Before
    public void setUp() {
        graph = new BipartiteWeightedGraph();
    }

    /**
     * Test of getYNodes method, of class BipartiteGraph.
     */
    @Test
    public void testGetAndAddNodes() {
        System.out.println("getYNodes");
        assertEquals(0, graph.getYNodes());
        assertEquals(0, graph.getXNodes());
        graph.addXNodes(5);
        graph.addYNodes(7);
        assertEquals(5, graph.getXNodes());
        assertEquals(7, graph.getYNodes());

        graph.addXNodes(3);
        assertEquals(8, graph.getXNodes());
    }

    /**
     * Test of setEdge method, of class BipartiteGraph.
     */
    @Test
    public void testSetAndRemoveConnection() {
        System.out.println("setConnection");
        graph.addXNodes(1);
        graph.addYNodes(2);
        graph.setEdge(0, 0, 5);
        graph.setEdge(0, 1, 7);
        assertEquals(5.0f, graph.getEdge(0, 0), 0.01);
        assertEquals(7.0f, graph.getEdge(0, 1), 0.01);

        Collection<Integer> set = graph.getX(0);
        assertTrue(set.contains(0));
        assertTrue(set.contains(1));
        assertEquals(2, set.size());

        Iterator<Integer> iter = graph.getY(0).iterator();
        assertEquals(0d, iter.next(), 0.01);
        assertFalse(iter.hasNext());

        iter = graph.getY(1).iterator();
        assertEquals(0d, iter.next(), 0.01);
        assertFalse(iter.hasNext());
    }
}
TOP

Related Classes of de.timefinder.algo.graph.BipartiteWeightedGraphTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.