changeset 334:252b458bd904

Add %!tests of dict creation and equality * pycall.cc: Add %!tests of dict creation and equality.
author Mike Miller <mtmiller@octave.org>
date Mon, 15 Aug 2016 14:19:15 -0700
parents 96b78e78a235
children 9b862844e6b7
files pycall.cc
diffstat 1 files changed, 18 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/pycall.cc	Mon Aug 15 13:20:15 2016 -0700
+++ b/pycall.cc	Mon Aug 15 14:19:15 2016 -0700
@@ -193,6 +193,24 @@
 %!error (pycall ("list", {1, 2, 3; 4, 5, 6}))
 %!error (pycall ("dict", {1, 2, 3}))
 
+## Test construction of dict from pyargs
+%!test
+%! a = pycall ("dict", pyargs ("a", 1, "b", 2, "c", 3));
+%! assert (sort (cell (pycall ("list", a.keys ()))), {"a", "b", "c"})
+%! assert (sort (double (pycall ("array.array", "d", a.values ()))), [1, 2, 3])
+
+## Test copy construction of dict from dict
+%!test
+%! a = pycall ("dict", pyargs ("a", 1, "b", 2, "c", 3));
+%! b = pycall ("dict", a);
+%! assert (isequal (a, b))
+
+## Test construction of dict from sequence of key value pairs
+%!test
+%! a = pycall ("dict", pyargs ("a", 1, "b", 2, "c", 3));
+%! b = pycall ("dict", pycall ("zip", {"a", "b", "c"}, {1, 2, 3}));
+%! assert (isequal (a, b))
+
 ## Test round trip type preservation / conversion
 %!test
 %! pyexec ("def roundtrip(x): return x");