@Test
public void testElementValueAttributes() {
Graph graph = new MultiGraph("g1");
Node A = graph.addNode("A");
assertEquals("A", A.getId());
assertEquals(0, A.getAttributeCount());
// Label attributes.
A.addAttribute("foo", "bar");
assertEquals(1, A.getAttributeCount());
assertTrue(A.hasAttribute("foo"));
assertTrue(A.hasAttribute("foo", String.class));
assertTrue(A.hasLabel("foo"));
assertFalse(A.hasNumber("foo"));
assertFalse(A.hasVector("foo"));
assertFalse(A.hasArray("foo"));
assertFalse(A.hasHash("foo"));
assertNotNull(A.getAttribute("foo"));
assertEquals("bar", A.getAttribute("foo"));
// Number attributes.
A.addAttribute("pi", 3.1415);
assertEquals(2, A.getAttributeCount());
assertTrue(A.hasAttribute("pi"));
assertTrue(A.hasAttribute("pi", Number.class));
assertFalse(A.hasLabel("pi"));
assertTrue(A.hasNumber("pi"));
assertFalse(A.hasVector("pi"));
assertFalse(A.hasArray("pi"));
assertFalse(A.hasHash("pi"));
assertNotNull(A.getAttribute("pi"));
assertEquals(3.1415, A.getAttribute("pi"));
assertEquals(new Double(3.1415), A.getAttribute("pi"));
A.setAttribute("pi", "3.1415");
assertEquals(3.1415, A.getNumber("pi"), 0);
// Vector of numbers.
ArrayList<Number> numbers = new ArrayList<Number>();
numbers.add(3);
numbers.add(1.4);
numbers.add(1.5f);
A.addAttribute("v", numbers);
assertEquals(3, A.getAttributeCount());
assertTrue(A.hasAttribute("v"));
assertTrue(A.hasAttribute("v", ArrayList.class));
assertFalse(A.hasLabel("v"));
assertFalse(A.hasNumber("v"));
assertTrue(A.hasVector("v"));
assertFalse(A.hasArray("v"));
assertFalse(A.hasHash("v"));
assertNotNull(A.getAttribute("v"));
assertEquals(numbers, A.getAttribute("v"));
assertEquals(numbers, A.getVector("v"));
// Hashes 1.
HashMap<String, String> map = new HashMap<String, String>();
map.put("A", "a");
map.put("B", "b");
map.put("C", "c");
A.addAttribute("map", map);
assertEquals(4, A.getAttributeCount());
assertTrue(A.hasAttribute("map"));
assertTrue(A.hasAttribute("map", HashMap.class));
assertFalse(A.hasLabel("map"));
assertFalse(A.hasNumber("map"));
assertFalse(A.hasVector("map"));
assertFalse(A.hasArray("map"));
assertTrue(A.hasHash("map"));
assertNotNull(A.getAttribute("map"));
assertEquals(map, A.getAttribute("map"));
assertEquals(map, A.getHash("map"));
// Hashes 2.
MyAttribute attr = new MyAttribute();
attr.put("A", "a");
attr.put("B", "b");
attr.put("C", "c");
A.addAttribute("ca", attr);
assertEquals(5, A.getAttributeCount());
assertTrue(A.hasAttribute("ca"));
assertTrue(A.hasAttribute("ca", MyAttribute.class));
assertFalse(A.hasLabel("ca"));
assertFalse(A.hasNumber("ca"));
assertFalse(A.hasVector("ca"));
assertFalse(A.hasArray("ca"));
assertTrue(A.hasHash("ca"));
assertNotNull(A.getAttribute("ca"));
assertEquals(attr, A.getAttribute("ca"));
assertEquals(attr, A.getHash("ca"));
// Clear
A.clearAttributes();
assertEquals(0, A.getAttributeCount());
}