From 0ce03b48a04a7766f8694b1de8a88073542dcc20 Mon Sep 17 00:00:00 2001 From: John R. Lenton Date: Sun, 12 Jan 2014 15:17:42 +0000 Subject: make sets iterable --- tests/basics/tests/set_iter.py | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 tests/basics/tests/set_iter.py (limited to 'tests') diff --git a/tests/basics/tests/set_iter.py b/tests/basics/tests/set_iter.py new file mode 100644 index 000000000..296017730 --- /dev/null +++ b/tests/basics/tests/set_iter.py @@ -0,0 +1,5 @@ +s = {1, 2, 3, 4} +l = list(s) +l.sort() +print(l) + -- cgit v1.2.3 From 19b14d3d8ae229f17f8b63825f96220db37e3770 Mon Sep 17 00:00:00 2001 From: John R. Lenton Date: Sun, 12 Jan 2014 15:29:11 +0000 Subject: Implemented set.add --- tests/basics/tests/set_add.py | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 tests/basics/tests/set_add.py (limited to 'tests') diff --git a/tests/basics/tests/set_add.py b/tests/basics/tests/set_add.py new file mode 100644 index 000000000..f2a372f30 --- /dev/null +++ b/tests/basics/tests/set_add.py @@ -0,0 +1,5 @@ +s = {1, 2, 3, 4} +print(s.add(5)) +l = list(s) +l.sort() +print(l) -- cgit v1.2.3 From 1d7fb2f21be8dd6f95e5889442a3735464c94dfb Mon Sep 17 00:00:00 2001 From: John R. Lenton Date: Sun, 12 Jan 2014 15:44:26 +0000 Subject: Implemented set.clear --- tests/basics/tests/set_clear.py | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 tests/basics/tests/set_clear.py (limited to 'tests') diff --git a/tests/basics/tests/set_clear.py b/tests/basics/tests/set_clear.py new file mode 100644 index 000000000..6fda93f0f --- /dev/null +++ b/tests/basics/tests/set_clear.py @@ -0,0 +1,3 @@ +s = {1, 2, 3, 4} +print(s.clear()) +print(list(s)) -- cgit v1.2.3 From 3b0bd87906eb301ebfe6588773ebfe07b0509ad8 Mon Sep 17 00:00:00 2001 From: John R. Lenton Date: Sun, 12 Jan 2014 15:56:25 +0000 Subject: Implemented set.copy --- tests/basics/tests/set_copy.py | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 tests/basics/tests/set_copy.py (limited to 'tests') diff --git a/tests/basics/tests/set_copy.py b/tests/basics/tests/set_copy.py new file mode 100644 index 000000000..2ea308b0d --- /dev/null +++ b/tests/basics/tests/set_copy.py @@ -0,0 +1,8 @@ +s = {1, 2, 3, 4} +t = s.copy() +s.add(5) +t.add(7) +for i in s, t: + l = list(i) + l.sort() + print(l) -- cgit v1.2.3 From 2a24172cdcdb5286c48afd6cf726548848e4840f Mon Sep 17 00:00:00 2001 From: John R. Lenton Date: Sun, 12 Jan 2014 16:39:39 +0000 Subject: Implemented set.discard --- tests/basics/tests/set_discard.py | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 tests/basics/tests/set_discard.py (limited to 'tests') diff --git a/tests/basics/tests/set_discard.py b/tests/basics/tests/set_discard.py new file mode 100644 index 000000000..baac26413 --- /dev/null +++ b/tests/basics/tests/set_discard.py @@ -0,0 +1,3 @@ +s = {1, 2} +print(s.discard(1)) +print(list(s)) -- cgit v1.2.3 From 032129f3b595f132046b9f4c6f108f1677aef944 Mon Sep 17 00:00:00 2001 From: John R. Lenton Date: Sun, 12 Jan 2014 17:07:17 +0000 Subject: Implemented set.difference and set.difference_update --- tests/basics/tests/set_difference.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 tests/basics/tests/set_difference.py (limited to 'tests') diff --git a/tests/basics/tests/set_difference.py b/tests/basics/tests/set_difference.py new file mode 100644 index 000000000..26976116f --- /dev/null +++ b/tests/basics/tests/set_difference.py @@ -0,0 +1,21 @@ +def report(s): + l = list(s) + l.sort() + print(l) + +l = [1, 2, 3, 4] +s = set(l) +outs = [s.difference(), + s.difference({1}), + s.difference({1}, [1, 2]), + s.difference({1}, {1, 2}, {2, 3})] +for out in outs: + report(out) + +s = set(l) +print(s.difference_update()) +report(s) +print(s.difference_update({1})) +report(s) +print(s.difference_update({1}, [2])) +report(s) -- cgit v1.2.3 From f1ae6b48fbc88d4acdbe1136f56c136f8e1b2991 Mon Sep 17 00:00:00 2001 From: John R. Lenton Date: Sun, 12 Jan 2014 17:54:03 +0000 Subject: Implemented set.intersection and set.intersection_update --- tests/basics/tests/set_intersection.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 tests/basics/tests/set_intersection.py (limited to 'tests') diff --git a/tests/basics/tests/set_intersection.py b/tests/basics/tests/set_intersection.py new file mode 100644 index 000000000..6f3dfc741 --- /dev/null +++ b/tests/basics/tests/set_intersection.py @@ -0,0 +1,12 @@ +def report(s): + l = list(s) + l.sort() + print(l) + +s = {1, 2, 3, 4} +report(s) +report(s.intersection({1, 3})) +report(s.intersection([3, 4])) + +print(s.intersection_update([1])) +report(s) -- cgit v1.2.3 From 4a08067c0c9c8417525e89eef4c3693cdc05b954 Mon Sep 17 00:00:00 2001 From: John R. Lenton Date: Sun, 12 Jan 2014 18:03:21 +0000 Subject: Implemented set.isdisjoint --- tests/basics/tests/set_isdisjoint.py | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 tests/basics/tests/set_isdisjoint.py (limited to 'tests') diff --git a/tests/basics/tests/set_isdisjoint.py b/tests/basics/tests/set_isdisjoint.py new file mode 100644 index 000000000..7fb7e769b --- /dev/null +++ b/tests/basics/tests/set_isdisjoint.py @@ -0,0 +1,6 @@ +s = {1, 2, 3, 4} +print(s.isdisjoint({1})) +print(s.isdisjoint([2])) +print(s.isdisjoint([])) +print(s.isdisjoint({7,8,9,10})) +print(s.isdisjoint([7,8,9,1])) -- cgit v1.2.3 From ae00d334c6222fa9716135967a7c512b03f08191 Mon Sep 17 00:00:00 2001 From: John R. Lenton Date: Sun, 12 Jan 2014 18:23:36 +0000 Subject: Implemented set.remove --- tests/basics/tests/set_isfooset.py | 5 +++++ tests/basics/tests/set_pop.py | 9 +++++++++ tests/basics/tests/set_remove.py | 9 +++++++++ 3 files changed, 23 insertions(+) create mode 100644 tests/basics/tests/set_isfooset.py create mode 100644 tests/basics/tests/set_pop.py create mode 100644 tests/basics/tests/set_remove.py (limited to 'tests') diff --git a/tests/basics/tests/set_isfooset.py b/tests/basics/tests/set_isfooset.py new file mode 100644 index 000000000..ce7952cd2 --- /dev/null +++ b/tests/basics/tests/set_isfooset.py @@ -0,0 +1,5 @@ +sets = [set(), {1}, {1, 2, 3}, {3, 4, 5}, {5, 6, 7}] +for i in sets: + for j in sets: + print(i.issubset(j)) + print(i.issuperset(j)) diff --git a/tests/basics/tests/set_pop.py b/tests/basics/tests/set_pop.py new file mode 100644 index 000000000..0cd478ce2 --- /dev/null +++ b/tests/basics/tests/set_pop.py @@ -0,0 +1,9 @@ +s = {1} +print(s.pop()) +try: + print(s.pop(), "!!!") +except KeyError: + pass +else: + print("Failed to raise KeyError") + diff --git a/tests/basics/tests/set_remove.py b/tests/basics/tests/set_remove.py new file mode 100644 index 000000000..208ab137f --- /dev/null +++ b/tests/basics/tests/set_remove.py @@ -0,0 +1,9 @@ +s = {1} +print(s.remove(1)) +print(list(s)) +try: + print(s.remove(1), "!!!") +except KeyError: + pass +else: + print("failed to raise KeyError") -- cgit v1.2.3 From 0de386bffec8acddcbe8c15913396035ea0b6405 Mon Sep 17 00:00:00 2001 From: John R. Lenton Date: Sun, 12 Jan 2014 19:39:48 +0000 Subject: Implemented set.update --- tests/basics/tests/set_symmetric_difference.py | 7 +++++++ tests/basics/tests/set_union.py | 1 + tests/basics/tests/set_update.py | 12 ++++++++++++ 3 files changed, 20 insertions(+) create mode 100644 tests/basics/tests/set_symmetric_difference.py create mode 100644 tests/basics/tests/set_union.py create mode 100644 tests/basics/tests/set_update.py (limited to 'tests') diff --git a/tests/basics/tests/set_symmetric_difference.py b/tests/basics/tests/set_symmetric_difference.py new file mode 100644 index 000000000..acf298385 --- /dev/null +++ b/tests/basics/tests/set_symmetric_difference.py @@ -0,0 +1,7 @@ +print({1,2}.symmetric_difference({2,3})) +print({1,2}.symmetric_difference([2,3])) +s = {1,2} +print(s.symmetric_difference_update({2,3})) +l = list(s) +l.sort() +print(l) diff --git a/tests/basics/tests/set_union.py b/tests/basics/tests/set_union.py new file mode 100644 index 000000000..2adcc972c --- /dev/null +++ b/tests/basics/tests/set_union.py @@ -0,0 +1 @@ +print({1}.union({2})) diff --git a/tests/basics/tests/set_update.py b/tests/basics/tests/set_update.py new file mode 100644 index 000000000..78cd76356 --- /dev/null +++ b/tests/basics/tests/set_update.py @@ -0,0 +1,12 @@ +def report(s): + l = list(s) + l.sort() + print(l) + +s = {1} +s.update() +report(s) +s.update([2]) +report(s) +s.update([1,3], [2,2,4]) +report(s) -- cgit v1.2.3 From be790f94d5c66b96aa99b09a83639507f037f0a3 Mon Sep 17 00:00:00 2001 From: John R. Lenton Date: Sun, 12 Jan 2014 23:09:10 +0000 Subject: Implemented set binary ops. --- tests/basics/tests/set_binop.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 tests/basics/tests/set_binop.py (limited to 'tests') diff --git a/tests/basics/tests/set_binop.py b/tests/basics/tests/set_binop.py new file mode 100644 index 000000000..46ecbcb63 --- /dev/null +++ b/tests/basics/tests/set_binop.py @@ -0,0 +1,29 @@ +def r(s): + l = list(s) + l.sort() + print(l) +s = {1, 2} +t = {2, 3} +r(s | t) +r(s ^ t) +r(s & t) +r(s - t) +u = s.copy() +u |= t +r(u) +u = s.copy() +u ^= t +r(u) +u = s.copy() +u &= t +r(u) +u = s.copy() +u -= t +r(u) + +print(s == t) +print(s != t) +print(s > t) +print(s >= t) +print(s < t) +print(s <= t) -- cgit v1.2.3 From 7244a1443930824b31498cd30f1840af648131c3 Mon Sep 17 00:00:00 2001 From: John R. Lenton Date: Sun, 12 Jan 2014 23:37:45 +0000 Subject: oops, nasty off-by-one in set_copy --- tests/basics/tests/set_binop.py | 51 +++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 25 deletions(-) (limited to 'tests') diff --git a/tests/basics/tests/set_binop.py b/tests/basics/tests/set_binop.py index 46ecbcb63..d0d0b8027 100644 --- a/tests/basics/tests/set_binop.py +++ b/tests/basics/tests/set_binop.py @@ -1,29 +1,30 @@ def r(s): l = list(s) l.sort() - print(l) -s = {1, 2} -t = {2, 3} -r(s | t) -r(s ^ t) -r(s & t) -r(s - t) -u = s.copy() -u |= t -r(u) -u = s.copy() -u ^= t -r(u) -u = s.copy() -u &= t -r(u) -u = s.copy() -u -= t -r(u) + return l +sets = [set(), {1}, {1, 2}, {1, 2, 3}, {2, 3}, {2, 3, 5}, {5}, {7}] +for s in sets: + for t in sets: + print(s, '|', t, '=', r(s | t)) + print(s, '^', t, '=', r(s ^ t)) + print(s, '&', t, '=', r(s & t)) + print(s, '-', t, '=', r(s - t)) + u = s.copy() + u |= t + print(s, "|=", t, '-->', r(u)) + u = s.copy() + u ^= t + print(s, "^=", t, '-->', r(u)) + u = s.copy() + u &= t + print(s, "&=", t, "-->", r(u)) + u = s.copy() + u -= t + print(s, "-=", t, "-->", r(u)) -print(s == t) -print(s != t) -print(s > t) -print(s >= t) -print(s < t) -print(s <= t) + print(s, '==', t, '=', s == t) + print(s, '!=', t, '=', s != t) + print(s, '>', t, '=', s > t) + print(s, '>=', t, '=', s >= t) + print(s, '<', t, '=', s < t) + print(s, '<=', t, '=', s <= t) -- cgit v1.2.3