@Override
    public Iterator<Integer> iterator() {
        return new Iterator<Integer>() {
            private int current = from;

            @Override
            public boolean hasNext() {
                return current < to;
            }

            @Override
            public Integer next() {
                if (!hasNext()) throw new NoSuchElementException();
                return current++;
            }
        };
    }
@Test
    void testIterator() {
        RangeSet rangeSet = new RangeSet(5, 10);
        Iterator<Integer> iterator = rangeSet.iterator();
        for (int i = 5; i < 10; i++) {
            assertTrue(iterator.hasNext());
            assertEquals(i, iterator.next());
        }
        assertFalse(iterator.hasNext());
        assertThrows(NoSuchElementException.class, iterator::next);
    }