Sample
set 1.1.3: Demonstrate that Set#<=> implements subset partial ordering rather than total ordering, returning nil for incomparable sets and causing Array#sort to raise ArgumentError.
Verified sample for gem set 1.1.3: Demonstrate that Set#<=> implements subset partial ordering rather than total ordering, returning nil for incomparable…
sha256:72cc01c64895659755d1fa04f846f49f48adf91a79aee92dd664dde5076fe8ed
This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured.
How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people.
MIT-0
Execution evidence
The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.
- Evidence basis
- Signed contract pass
- Verification receipts
- 2
- Signing keys that built it
- 2
Declared environment
ruby linux x64 ruby ruby bundler
Verification-run environments
| Environment | Contract | Stages | Run |
|---|---|---|---|
| ruby 3 · linux debian/x64 · docker ed25519:d91480838ac982c9 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · rubygems@1 |
2026-08-17 |
| ruby 3 · linux debian/x64 · docker ed25519:2175b912ea1c23b1 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · rubygems@1 |
2026-08-18 |
Case
HOW- Goal
- Demonstrate that Set#<=> implements subset partial ordering rather than total ordering, returning nil for incomparable sets and causing Array#sort to raise ArgumentError.
- Packages
- Symbols
-
- set
- Set
- Set#<=>
- Environment
- ruby
- Created
- 2026-08-17T07:23:19Z
Contract
- Set#<=> returns nil when neither set is a subset of the other, which causes Array#sort on incomparable sets to raise ArgumentError.
- Set#<=> returns -1, 0, or 1 only when sets are in a proper subset, equal, or proper superset relationship.
- Array#sort on an array of sets succeeds only when all elements can be ordered by subset inclusion.
Files
- Gemfile
- Gemfile.lock
- NOTES.md
- csx.json
- test/contract.rb
Source
source "https://rubygems.org"
gem "set", "1.1.3"
GEM
remote: https://rubygems.org/
specs:
set (1.1.3)
PLATFORMS
ruby
x64-mingw-ucrt
DEPENDENCIES
set (= 1.1.3)
CHECKSUMS
bundler (4.0.18) sha256=02d9a17429de1847b4e0c9f27a9ee4b20c0a74c0a641b4e77195d6019e3618ac
set (1.1.3) sha256=12bbbd31c8b177d55ac0314bcc7f4c473276b06e8a2dcfdc14326e73ce7769ce
BUNDLED WITH
4.0.18
# Set Behavior Notes
## Known Solutions Search
A search via `search_known_solution` for `set` returned existing published samples:
- `sha256:f6a3b9fffc2feae50a88bbf1e67fb2df72ee881835f753c7b1e0dd1960834188`: preloading removed `sorted_set` via `RUBYOPT=-rsorted_set` fails startup.
- `sha256:c3ebad077aa01c12e583e57f127c53912b03d9730d22c45a627de462968ed9b7`: element hash mutation causing stale Set membership recoverable with `Set#reset`.
- `sha256:be568ae4dfa6ca70997019d57f8927ef41a1281a77737965d777cc3fee8ad853`: `Set#replace` resetting `compare_by_identity` state.
To avoid duplicating existing coverage, this sample targets the comparison semantics of `Set#<=>` and its interaction with `Array#sort`.
## Pinned Release
- Gem: `set`
- Version: `1.1.3`
## Observed Behavior
`Set#<=>` implements a partial ordering based strictly on subset/superset relations:
- It returns `-1` if the receiver is a proper subset of the argument (`Set[1, 2] <=> Set[1, 2, 3]`).
- It returns `1` if the receiver is a proper superset of the argument (`Set[1, 2, 3] <=> Set[1, 2]`).
- It returns `0` if both sets contain the same elements (`Set[1, 2] <=> Set[2, 1]`).
- It returns `nil` when comparing against a non-Set object or when neither set is a subset of the other (`Set[1, 2] <=> Set[1, 4]` or `Set[1, 2] <=> Set[3]`), even when their sizes differ.
## Failure Mode
When code naively assumes `Set#<=>` provides a total ordering across arbitrary sets (e.g., sorting an array of sets with `[Set[1, 2], Set[1, 4]].sort`), execution fails loudly with:
`ArgumentError: comparison of Set with Set failed`
Only collections of sets that form a strict subset hierarchy can be sorted with `Array#sort`.
{"case":{"believed":"Set#\u003c=\u003e provides a total ordering across any sets so arrays of sets can be sorted with Array#sort.","caseId":"case:sha256:7ae5594678c9ea03fac069feca35dc721d33f5fbb5bbeaeb72d08778c84135eb","contract":["Set#\u003c=\u003e returns nil when neither set is a subset of the other, which causes Array#sort on incomparable sets to raise ArgumentError.","Set#\u003c=\u003e returns -1, 0, or 1 only when sets are in a proper subset, equal, or proper superset relationship.","Array#sort on an array of sets succeeds only when all elements can be ordered by subset inclusion."],"goal":"Demonstrate that Set#\u003c=\u003e implements subset partial ordering rather than total ordering, returning nil for incomparable sets and causing Array#sort to raise ArgumentError.","kind":"HOW","packages":["pkg:gem/set@1.1.3"],"schemaVersion":1,"symbols":["set","Set","Set#\u003c=\u003e"]},"contractCommand":["ruby","test/contract.rb"],"environment":{"arch":"x64","ecosystem":"gem","executionContext":"ruby","language":"ruby","os":"linux","packageManager":"bundler","runtime":"ruby","schemaVersion":1},"license":"MIT-0","packages":["pkg:gem/set@1.1.3"],"schemaVersion":1,"symbols":["set","Set","Set#\u003c=\u003e"],"verifierAdapter":"rubygems@1"}
# frozen_string_literal: true
require "set"
def assert(condition, message)
raise "ASSERTION FAILED: #{message}" unless condition
end
# Verify resolved version
version = Gem.loaded_specs["set"]&.version&.to_s || Set::VERSION
assert(version == "1.1.3", "expected set gem version 1.1.3, got #{version}")
# Set#<=> defines a partial order based on subset/superset relations:
# - proper subset: -1
# - proper superset: 1
# - equal: 0
# - incomparable: nil
s1 = Set[1, 2]
s2 = Set[1, 2, 3]
s3 = Set[2, 1]
s4 = Set[1, 4]
s5 = Set[3]
# 1. Proper subset and superset comparisons return -1 and 1
assert((s1 <=> s2) == -1, "subset <=> superset should return -1")
assert((s2 <=> s1) == 1, "superset <=> subset should return 1")
# 2. Equal sets return 0 regardless of insertion order
assert((s1 <=> s3) == 0, "equal sets should return 0")
# 3. Incomparable sets (neither is a subset of the other) return nil
assert((s1 <=> s4).nil?, "partially overlapping sets should return nil")
assert((s1 <=> s5).nil?, "disjoint sets of different sizes should return nil")
# 4. Comparison against non-Set objects returns nil
assert((s1 <=> [1, 2]).nil?, "comparing Set with Array should return nil")
# 5. Sorting sets that form a subset chain succeeds
chain = [Set[1, 2, 3], Set[1], Set[1, 2]]
sorted_chain = chain.sort
assert(sorted_chain == [Set[1], Set[1, 2], Set[1, 2, 3]], "subset chain should sort by inclusion")
# 6. Sorting incomparable sets fails loudly with ArgumentError
sort_error = nil
begin
[s1, s4].sort
rescue ArgumentError => e
sort_error = e
end
assert(!sort_error.nil?, "sorting incomparable sets must raise ArgumentError")
assert(sort_error.message.include?("comparison of Set with Set failed"),
"expected 'comparison of Set with Set failed' error message")
puts "contract passed"