Skip to content

Commit f2e0d0b

Browse files
committed
Sync custom-set with problem-specifications
1 parent 3c6e571 commit f2e0d0b

4 files changed

Lines changed: 318 additions & 148 deletions

File tree

exercises/practice/custom-set/.docs/instructions.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
Create a custom set type.
44

5-
Sometimes it is necessary to define a custom data structure of some
6-
type, like a set. In this exercise you will define your own set. How it
7-
works internally doesn't matter, as long as it behaves like a set of
8-
unique elements.
5+
Sometimes it is necessary to define a custom data structure of some type, like a set.
6+
In this exercise you will define your own set.
7+
How it works internally doesn't matter, as long as it behaves like a set of unique elements.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
use custom_set::CustomSet;
2+
{% for test in cases %}
3+
#[test]
4+
{% if loop.index != 1 -%}
5+
#[ignore]
6+
{% endif -%}
7+
fn {{ test.description | slugify | replace(from="-", to="_") }}() {
8+
{%- if test.property == "empty" %}
9+
let set = CustomSet::<i32>::new(&{{ test.input.set | json_encode() }});
10+
assert!(
11+
{%- if not test.expected -%} ! {%- endif -%}
12+
set.is_empty());
13+
{%- elif test.property == "contains" %}
14+
let set = CustomSet::<i32>::new(&{{ test.input.set | json_encode() }});
15+
assert!(
16+
{%- if not test.expected -%} ! {%- endif -%}
17+
set.contains(&{{ test.input.element }}));
18+
{%- elif test.property == "subset" %}
19+
let set_1 = CustomSet::<i32>::new(&{{ test.input.set1 | json_encode() }});
20+
let set_2 = CustomSet::<i32>::new(&{{ test.input.set2 | json_encode() }});
21+
assert!(
22+
{%- if not test.expected -%} ! {%- endif -%}
23+
set_1.is_subset(&set_2));
24+
{%- elif test.property == "disjoint" %}
25+
let set_1 = CustomSet::<i32>::new(&{{ test.input.set1 | json_encode() }});
26+
let set_2 = CustomSet::<i32>::new(&{{ test.input.set2 | json_encode() }});
27+
assert!(
28+
{%- if not test.expected -%} ! {%- endif -%}
29+
set_1.is_disjoint(&set_2));
30+
{%- elif test.property == "equal" %}
31+
let set_1 = CustomSet::<i32>::new(&{{ test.input.set1 | json_encode() }});
32+
let set_2 = CustomSet::<i32>::new(&{{ test.input.set2 | json_encode() }});
33+
{% if test.expected -%}
34+
assert_eq!(set_1, set_2);
35+
{%- else -%}
36+
assert_ne!(set_1, set_2);
37+
{%- endif %}
38+
{%- elif test.property == "add" %}
39+
let mut set = CustomSet::<i32>::new(&{{ test.input.set | json_encode() }});
40+
set.add({{ test.input.element }});
41+
let expected = CustomSet::<i32>::new(&{{ test.expected | json_encode() }});
42+
assert_eq!(set, expected);
43+
{%- elif test.property == "intersection" %}
44+
let set_1 = CustomSet::<i32>::new(&{{ test.input.set1 | json_encode() }});
45+
let set_2 = CustomSet::<i32>::new(&{{ test.input.set2 | json_encode() }});
46+
let expected = CustomSet::<i32>::new(&{{ test.expected | json_encode() }});
47+
assert_eq!(set_1.intersection(&set_2), expected);
48+
{%- elif test.property == "difference" %}
49+
let set_1 = CustomSet::<i32>::new(&{{ test.input.set1 | json_encode() }});
50+
let set_2 = CustomSet::<i32>::new(&{{ test.input.set2 | json_encode() }});
51+
let expected = CustomSet::<i32>::new(&{{ test.expected | json_encode() }});
52+
assert_eq!(set_1.difference(&set_2), expected);
53+
{%- elif test.property == "union" %}
54+
let set_1 = CustomSet::<i32>::new(&{{ test.input.set1 | json_encode() }});
55+
let set_2 = CustomSet::<i32>::new(&{{ test.input.set2 | json_encode() }});
56+
let expected = CustomSet::<i32>::new(&{{ test.expected | json_encode() }});
57+
assert_eq!(set_1.union(&set_2), expected);
58+
{%- endif %}
59+
}
60+
{% endfor -%}
Lines changed: 106 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,124 @@
1-
# This is an auto-generated file. Regular comments will be removed when this
2-
# file is regenerated. Regenerating will not touch any manually added keys,
3-
# so comments can be added in a "comment" key.
1+
# This is an auto-generated file.
2+
#
3+
# Regenerating this file via `configlet sync` will:
4+
# - Recreate every `description` key/value pair
5+
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
6+
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
7+
# - Preserve any other key/value pair
8+
#
9+
# As user-added comments (using the # character) will be removed when this file
10+
# is regenerated, comments can be added via a `comment` key.
411

512
[20c5f855-f83a-44a7-abdd-fe75c6cf022b]
6-
description = "sets with no elements are empty"
13+
description = "Returns true if the set contains no elements -> sets with no elements are empty"
714

815
[d506485d-5706-40db-b7d8-5ceb5acf88d2]
9-
description = "sets with elements are not empty"
16+
description = "Returns true if the set contains no elements -> sets with elements are not empty"
1017

1118
[759b9740-3417-44c3-8ca3-262b3c281043]
12-
description = "nothing is contained in an empty set"
19+
description = "Sets can report if they contain an element -> nothing is contained in an empty set"
20+
21+
[f83cd2d1-2a85-41bc-b6be-80adbff4be49]
22+
description = "Sets can report if they contain an element -> when the element is in the set"
23+
24+
[93423fc0-44d0-4bc0-a2ac-376de8d7af34]
25+
description = "Sets can report if they contain an element -> when the element is not in the set"
26+
27+
[c392923a-637b-4495-b28e-34742cd6157a]
28+
description = "A set is a subset if all of its elements are contained in the other set -> empty set is a subset of another empty set"
29+
30+
[5635b113-be8c-4c6f-b9a9-23c485193917]
31+
description = "A set is a subset if all of its elements are contained in the other set -> empty set is a subset of non-empty set"
32+
33+
[832eda58-6d6e-44e2-92c2-be8cf0173cee]
34+
description = "A set is a subset if all of its elements are contained in the other set -> non-empty set is not a subset of empty set"
35+
36+
[c830c578-8f97-4036-b082-89feda876131]
37+
description = "A set is a subset if all of its elements are contained in the other set -> set is a subset of set with exact same elements"
38+
39+
[476a4a1c-0fd1-430f-aa65-5b70cbc810c5]
40+
description = "A set is a subset if all of its elements are contained in the other set -> set is a subset of larger set with same elements"
41+
42+
[d2498999-3e46-48e4-9660-1e20c3329d3d]
43+
description = "A set is a subset if all of its elements are contained in the other set -> set is not a subset of set that does not contain its elements"
44+
45+
[7d38155e-f472-4a7e-9ad8-5c1f8f95e4cc]
46+
description = "Sets are disjoint if they share no elements -> the empty set is disjoint with itself"
47+
48+
[7a2b3938-64b6-4b32-901a-fe16891998a6]
49+
description = "Sets are disjoint if they share no elements -> empty set is disjoint with non-empty set"
50+
51+
[589574a0-8b48-48ea-88b0-b652c5fe476f]
52+
description = "Sets are disjoint if they share no elements -> non-empty set is disjoint with empty set"
53+
54+
[febeaf4f-f180-4499-91fa-59165955a523]
55+
description = "Sets are disjoint if they share no elements -> sets are not disjoint if they share an element"
56+
57+
[0de20d2f-c952-468a-88c8-5e056740f020]
58+
description = "Sets are disjoint if they share no elements -> sets are disjoint if they share no elements"
1359

1460
[4bd24adb-45da-4320-9ff6-38c044e9dff8]
15-
description = "empty sets are equal"
61+
description = "Sets with the same elements are equal -> empty sets are equal"
62+
63+
[f65c0a0e-6632-4b2d-b82c-b7c6da2ec224]
64+
description = "Sets with the same elements are equal -> empty set is not equal to non-empty set"
65+
66+
[81e53307-7683-4b1e-a30c-7e49155fe3ca]
67+
description = "Sets with the same elements are equal -> non-empty set is not equal to empty set"
1668

1769
[d57c5d7c-a7f3-48cc-a162-6b488c0fbbd0]
18-
description = "sets with the same elements are equal"
70+
description = "Sets with the same elements are equal -> sets with the same elements are equal"
1971

2072
[dd61bafc-6653-42cc-961a-ab071ee0ee85]
21-
description = "sets with different elements are not equal"
73+
description = "Sets with the same elements are equal -> sets with different elements are not equal"
74+
75+
[06059caf-9bf4-425e-aaff-88966cb3ea14]
76+
description = "Sets with the same elements are equal -> set is not equal to larger set with same elements"
2277

2378
[8a677c3c-a658-4d39-bb88-5b5b1a9659f4]
24-
description = "add to empty set"
79+
description = "Unique elements can be added to a set -> add to empty set"
80+
81+
[0903dd45-904d-4cf2-bddd-0905e1a8d125]
82+
description = "Unique elements can be added to a set -> add to non-empty set"
83+
84+
[b0eb7bb7-5e5d-4733-b582-af771476cb99]
85+
description = "Unique elements can be added to a set -> adding an existing element does not change the set"
86+
87+
[893d5333-33b8-4151-a3d4-8f273358208a]
88+
description = "Intersection returns a set of all shared elements -> intersection of two empty sets is an empty set"
89+
90+
[d739940e-def2-41ab-a7bb-aaf60f7d782c]
91+
description = "Intersection returns a set of all shared elements -> intersection of an empty set and non-empty set is an empty set"
92+
93+
[3607d9d8-c895-4d6f-ac16-a14956e0a4b7]
94+
description = "Intersection returns a set of all shared elements -> intersection of a non-empty set and an empty set is an empty set"
2595

2696
[b5120abf-5b5e-41ab-aede-4de2ad85c34e]
27-
description = "intersection of two sets with no shared elements is an empty set"
97+
description = "Intersection returns a set of all shared elements -> intersection of two sets with no shared elements is an empty set"
2898

2999
[af21ca1b-fac9-499c-81c0-92a591653d49]
30-
description = "intersection of two sets with shared elements is a set of the shared elements"
100+
description = "Intersection returns a set of all shared elements -> intersection of two sets with shared elements is a set of the shared elements"
101+
102+
[c5e6e2e4-50e9-4bc2-b89f-c518f015b57e]
103+
description = "Difference (or Complement) of a set is a set of all elements that are only in the first set -> difference of two empty sets is an empty set"
104+
105+
[2024cc92-5c26-44ed-aafd-e6ca27d6fcd2]
106+
description = "Difference (or Complement) of a set is a set of all elements that are only in the first set -> difference of empty set and non-empty set is an empty set"
107+
108+
[e79edee7-08aa-4c19-9382-f6820974b43e]
109+
description = "Difference (or Complement) of a set is a set of all elements that are only in the first set -> difference of a non-empty set and an empty set is the non-empty set"
110+
111+
[c5ac673e-d707-4db5-8d69-7082c3a5437e]
112+
description = "Difference (or Complement) of a set is a set of all elements that are only in the first set -> difference of two non-empty sets is a set of elements that are only in the first set"
113+
114+
[c45aed16-5494-455a-9033-5d4c93589dc6]
115+
description = "Union returns a set of all elements in either set -> union of empty sets is an empty set"
116+
117+
[9d258545-33c2-4fcb-a340-9f8aa69e7a41]
118+
description = "Union returns a set of all elements in either set -> union of an empty set and non-empty set is the non-empty set"
119+
120+
[3aade50c-80c7-4db8-853d-75bac5818b83]
121+
description = "Union returns a set of all elements in either set -> union of a non-empty set and empty set is the non-empty set"
122+
123+
[a00bb91f-c4b4-4844-8f77-c73e2e9df77c]
124+
description = "Union returns a set of all elements in either set -> union of non-empty sets contains all unique elements"

0 commit comments

Comments
 (0)