Skip to content
Browse files

adds different namespaces for mapping Nodes Edges and Supplies

  • Loading branch information...
1 parent 9bbed5a commit f116f3b24f97e94b458df98d612f9d38782ed687 @neilmanuell committed May 22, 2012
View
2 src/circuit/api/CircuitBoardConfig.as
@@ -6,6 +6,6 @@ public interface CircuitBoardConfig
function getNodeInstance( id:String ):Node
- function getSuppleyInstance( id:String ):Supply;
+ function getSupplyInstance( id:String ):Supply;
}
}
View
20 src/circuit/boards/SimpleCircuitBoard.as
@@ -25,13 +25,17 @@ public class SimpleCircuitBoard implements CircuitBoard, CircuitBoardConfig
private const _pathfinder:CircuitPathFinder = new CircuitPathFinder();
private var _hasChanged:Boolean = false;
private var _isPathFinding:Boolean = false;
+ private const NODE_NAMESPACE:String = "node::";
+ private const EDGE_NAMESPACE:String = "edge::";
+ private const SUPPLY_NAMESPACE:String = "supply::";
public function getEdgeInstance( id:String ):Edge
{
- if ( _map[id] != null )return _map[id];
+ const key:String = EDGE_NAMESPACE + id;
+ if ( _map[key] != null )return _map[key];
const edge:Edge = new SimpleBreakerEdge( id );
- _map[id] = edge;
+ _map[key] = edge;
addEdge( edge );
return edge;
}
@@ -43,9 +47,10 @@ public class SimpleCircuitBoard implements CircuitBoard, CircuitBoardConfig
public function getNodeInstance( id:String ):Node
{
- if ( _map[id] != null )return _map[id];
+ const key:String = NODE_NAMESPACE + id;
+ if ( _map[key] != null )return _map[key];
const node:Node = new SimpleCircuitNode( id );
- _map[id] = node;
+ _map[key] = node;
addNode( node );
return node;
}
@@ -55,11 +60,12 @@ public class SimpleCircuitBoard implements CircuitBoard, CircuitBoardConfig
return _nodes.has( node );
}
- public function getSuppleyInstance( id:String ):Supply
+ public function getSupplyInstance( id:String ):Supply
{
- if ( _map[id] != null )return _map[id];
+ const key:String = SUPPLY_NAMESPACE + id;
+ if ( _map[key] != null )return _map[key];
const supply:Supply = new SimplePowerSupply( id );
- _map[id] = supply;
+ _map[key] = supply;
addSupply( supply );
return supply
}
View
30 tests/circuit/boards/CircuitBoardConfigTest.as
@@ -5,6 +5,7 @@ import circuit.api.Node;
import circuit.api.Supply;
import org.hamcrest.assertThat;
+import org.hamcrest.core.not;
import org.hamcrest.object.instanceOf;
import org.hamcrest.object.isTrue;
import org.hamcrest.object.strictlyEqualTo;
@@ -82,29 +83,40 @@ public class CircuitBoardConfigTest
}
[Test]
- public function getSuppleyInstance_returns_instanceOf_Supply():void
+ public function getSupplyInstance_returns_instanceOf_Supply():void
{
- assertThat( _classUnderTest.getSuppleyInstance( TEST ), instanceOf( Supply ) );
+ assertThat( _classUnderTest.getSupplyInstance( TEST ), instanceOf( Supply ) );
}
[Test]
- public function getSuppleyInstance_returns_Supply_with_passed_ID():void
+ public function getSupplyInstance_returns_Supply_with_passed_ID():void
{
- assertThat( _classUnderTest.getSuppleyInstance( TEST ).id, TEST );
+ assertThat( _classUnderTest.getSupplyInstance( TEST ).id, TEST );
}
[Test]
- public function getSuppleyInstance_registers_Supply():void
+ public function getSupplyInstance_registers_Supply():void
{
- const supply:Supply = _classUnderTest.getSuppleyInstance( TEST );
+ const supply:Supply = _classUnderTest.getSupplyInstance( TEST );
assertThat( _classUnderTest.hasSupply( supply ), isTrue() );
}
[Test]
- public function getSuppleyInstance_returns_same_Supply_inst():void
+ public function getSupplyInstance_returns_same_Supply_inst():void
{
- const supply:Supply = _classUnderTest.getSuppleyInstance( TEST );
- assertThat( supply, strictlyEqualTo( _classUnderTest.getSuppleyInstance( TEST ) ) );
+ const supply:Supply = _classUnderTest.getSupplyInstance( TEST );
+ assertThat( supply, strictlyEqualTo( _classUnderTest.getSupplyInstance( TEST ) ) );
+ }
+
+ [Test]
+ public function Nodes_Edges_Supplies_are_mapped_with_different_namespaces():void
+ {
+ const node:Node = _classUnderTest.getNodeInstance( TEST );
+ const edge:Edge = _classUnderTest.getEdgeInstance( TEST );
+ const supply:Supply = _classUnderTest.getSupplyInstance( TEST );
+ assertThat( node, not( edge ) );
+ assertThat( edge, not( supply ) );
+ assertThat( node, not( supply ) );
}
}
}

0 comments on commit f116f3b

Please sign in to comment.
Something went wrong with that request. Please try again.