Mercurial > hg > octave-lyh
changeset 9392:26c72e899228
Add tests for preservation of key order
author | Thorsten Meyer <thorsten.meyier@gmx.de> |
---|---|
date | Wed, 24 Jun 2009 21:33:24 +0200 |
parents | 333b31ce3434 |
children | d6c99b2ee941 |
files | src/ChangeLog src/oct-map.cc |
diffstat | 2 files changed, 52 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2009-06-24 Thorsten Meyer <thorsten.meyier@gmx.de> + + * oct-map.cc (Octave_map::squeeze, Octave_map::permute, + Octave_map::transpose, Octave_map::reshape, Octave_map::concat, + Octave_map::index): Add tests for preservation of key order in + struct arrays. + 2009-06-24 Jaroslav Hajek <highegg@gmail.com> * pt-mat.cc (get_concat_class): Use empty string as zero value.
--- a/src/oct-map.cc +++ b/src/oct-map.cc @@ -70,6 +70,13 @@ return retval; } +/* +%!# test preservation of keys by squeeze +%!test +%! x(1,1,1,1).d = 10; x(3,5,1,7).a = "b"; x(2,4,1,7).f = 27; +%! assert (fieldnames (squeeze (x)), {"d"; "a"; "f"}); +*/ + Octave_map Octave_map::permute (const Array<int>& vec, bool inv) const { @@ -91,6 +98,13 @@ return retval; } +/* +%!# test preservation of key order by permute +%!test +%! x(1,1,1,1).d = 10; x(3,5,1,7).a = "b"; x(2,4,1,7).f = 27; +%! assert (fieldnames (permute (x, [3, 4, 1, 2])), {"d"; "a"; "f"}); +*/ + Cell& Octave_map::contents (const std::string& k) { @@ -165,6 +179,15 @@ return retval; } +/* +%!# test preservation of key order by transpose +%!test +%! x(1,1).d = 10; x(3,5).a = "b"; x(2,4).f = 27; +%! assert (fieldnames (transpose (x)), {"d"; "a"; "f"}); +%! assert (fieldnames (x'), {"d"; "a"; "f"}); +%! assert (fieldnames (x.'), {"d"; "a"; "f"}); +*/ + Octave_map Octave_map::reshape (const dim_vector& new_dims) const { @@ -186,6 +209,13 @@ return retval; } +/* +%!# test preservation of key order by reshape +%!test +%! x(1,1).d = 10; x(4,6).a = "b"; x(2,4).f = 27; +%! assert (fieldnames (reshape (x, 3, 8)), {"d"; "a"; "f"}); +*/ + void Octave_map::resize (const dim_vector& dv, bool fill) { @@ -256,6 +286,14 @@ return retval; } +/* +%!# test preservation of key order by concatenation +%!test +%! x(1, 1).d = 10; x(4, 6).a = "b"; x(2, 4).f = 27; +%! y(1, 6).f = 11; y(1, 6).a = "c"; y(1, 6).d = 33; +%! assert (fieldnames ([x; y]), {"d"; "a"; "f"}); +*/ + static bool keys_ok (const Octave_map& a, const Octave_map& b, string_vector& keys) { @@ -490,6 +528,13 @@ } /* +%!# test preservation of key order by indexing +%!test +%! x(1, 1).d = 10; x(4, 6).a = "b"; x(2, 4).f = 27; +%! assert (fieldnames (x([1, 2], [2:5])), {"d"; "a"; "f"}); +*/ + +/* ;;; Local Variables: *** ;;; mode: C++ *** ;;; End: ***