Files
mercury/tests/hard_coded/bitmap_test.exp
Simon Taylor d73e2187fb Add bit_buffers to the standard library. A bit_buffer
Estimated hours taken: 90
Branches: main

NEWS:
library/bit_buffer.m:
library/bit_buffer.read.m:
library/bit_buffer.write.m:
	Add bit_buffers to the standard library.  A bit_buffer
	provides a bit-oriented interface to byte streams.
	These will be used as a base for write_binary and read_binary.

library/stream.m:
	Add class which supports reading multiple items at once into
	a store.

	Clarify the blocking behaviour of `put' and `get'.

	Document the behaviour of subsequent calls to `get'
	after a call returns eof or an error.

library/bitmap.m:
	Add a shorthand for `new(N, no)'.

	Add `shrink_without_copying' to destructively shrink a bitmap
	without copying the data.

	Add a function `append_list' to condense a list of bitmaps.

	Improve bounds error messages.

	Clean up the handling of zero-length bit ranges.

	Add type `bitmap.slice' to represent a segment of a bitmap,
	and functions to create slices.

library/io.m:
	Change the interface of io.read_bitmap to conform to
	the stream.bulk_reader interface, by not returning the
	bitmap inside the return code.  The bitmap is still
	valid (although maybe not completely filled) no matter
	what result is returned.

	Add io.read_binary_file_as_bitmap/N.

library/library.m:
	Add recent additions to the list of library modules.

library/Mercury.options:
	Use "+=" rather than "=" when setting target-specific
	options to allow them to be added to be Mmake.params.

tests/hard_coded/Mmakefile:
tests/hard_coded/bit_buffer_test.m:
tests/hard_coded/bit_buffer_test.exp:
	Test case.

tests/hard_coded/bitmap_test.m:
tests/hard_coded/bitmap_simple.m:
tests/hard_coded/bitmap_test.exp:
	Update for change to io.read_bitmap.

	Test bounds error messages.
2007-05-30 02:47:10 +00:00

250 lines
18 KiB
Plaintext

Single byte bitmap
1111
yes
1011
no
1001
1001
0101
0101
Multi-byte bitmap
00000000.00000000.0000
01000000.00000000.0000
01010010.10101000.0100
1010010101
101010000100
01010001.01010111.1000
01010011.01010111.1000
10101100.10101000.0111
<32:ACA87FFF>
"<32:ACA87FFF>"
Longer bitmap
10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110
10111010.10111001.01111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110
non-overlapping copy_bits
10111010.10111001.01111001.01000110.10111001.01000110.10111001.01000110.10010111.10010100.01101011.10010100.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110
testing builtin.copy
10111010.10111001.01111001.01000110.10111001.01000110.10111001.01000110.10010111.10010100.01101011.10010100.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110
Copy succeeded
Test simple aligned byte block copy.
Copy 8 64 32
Copy to zeroed bitmap
00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.01000110.10111001.01000110.10111001.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.0000000
Copy to filled bitmap
11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.01000110.10111001.01000110.10111001.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.1111111
Copy to alternating bitmap
10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.01000110.10111001.01000110.10111001.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.0101010
Copy to same bitmap
10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.01000110.10111001.01000110.10111001.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.0111001
Test byte block copy with extra bits on ends.
Copy 6 62 36
Copy to zeroed bitmap
00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000001.01000110.10111001.01000110.10111001.01000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.0000000
Copy to filled bitmap
11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111101.01000110.10111001.01000110.10111001.01111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.1111111
Copy to alternating bitmap
10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.01000110.10111001.01000110.10111001.01101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.0101010
Copy to same bitmap
10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000101.01000110.10111001.01000110.10111001.01111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.0111001
Test unaligned copy.
Copy 7 64 32
Copy to zeroed bitmap
00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.10100011.01011100.10100011.01011100.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.0000000
Copy to filled bitmap
11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.10100011.01011100.10100011.01011100.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.1111111
Copy to alternating bitmap
10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.10100011.01011100.10100011.01011100.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.0101010
Copy to same bitmap
10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10100011.01011100.10100011.01011100.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.0111001
Test unaligned copy with extra bits on ends.
Copy 7 67 36
Copy to zeroed bitmap
00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00010100.01101011.10010100.01101011.10010100.00000000.00000000.00000000.00000000.00000000.00000000.00000000.0000000
Copy to filled bitmap
11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11110100.01101011.10010100.01101011.10010101.11111111.11111111.11111111.11111111.11111111.11111111.11111111.1111111
Copy to alternating bitmap
10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.10110100.01101011.10010100.01101011.10010100.01010101.10101010.01010101.10101010.01010101.10101010.01010101.0101010
Copy to same bitmap
10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10110100.01101011.10010100.01101011.10010101.01000110.10111001.01000110.10111001.01000110.10111001.01000110.0111001
Test overlapping aligned byte block copy.
Copy 8 0 36
Copy to zeroed bitmap
01000110.10111001.01000110.10111001.01000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.0000000
Copy to filled bitmap
01000110.10111001.01000110.10111001.01001111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.1111111
Copy to alternating bitmap
01000110.10111001.01000110.10111001.01001010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.0101010
Copy to same bitmap
01000110.10111001.01000110.10111001.01001001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.0111001
Test overlapping aligned byte block copy.
Copy 0 8 36
Copy to zeroed bitmap
00000000.10111001.01000110.10111001.01000110.10110000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.0000000
Copy to filled bitmap
11111111.10111001.01000110.10111001.01000110.10111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.1111111
Copy to alternating bitmap
10101010.10111001.01000110.10111001.01000110.10110101.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.0101010
Copy to same bitmap
10111001.10111001.01000110.10111001.01000110.10110110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.0111001
Test overlapping unaligned copy.
Copy 2 1 36
Copy to zeroed bitmap
01110010.10001101.01110010.10001101.01110000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.0000000
Copy to filled bitmap
11110010.10001101.01110010.10001101.01110111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.1111111
Copy to alternating bitmap
11110010.10001101.01110010.10001101.01110010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.0101010
Copy to same bitmap
11110010.10001101.01110010.10001101.01110001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.0111001
Test overlapping unaligned copy.
Copy 1 2 36
Copy to zeroed bitmap
00011100.10100011.01011100.10100011.01011100.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.0000000
Copy to filled bitmap
11011100.10100011.01011100.10100011.01011111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.1111111
Copy to alternating bitmap
10011100.10100011.01011100.10100011.01011110.01010101.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.0101010
Copy to same bitmap
10011100.10100011.01011100.10100011.01011101.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.0111001
Test copy to same position.
Copy 1 1 36
Copy to zeroed bitmap
00111001.01000110.10111001.01000110.10111000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.0000000
Copy to filled bitmap
10111001.01000110.10111001.01000110.10111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.1111111
Copy to alternating bitmap
10111001.01000110.10111001.01000110.10111010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.0101010
Copy to same bitmap
10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.0111001
Test copy to end of bitmap.
Copy 0 1 166
Copy to zeroed bitmap
01011100.10100011.01011100.10100011.01011100.10100011.01011100.10100011.01011100.10100011.01011100.10100011.01011100.10100011.01011100.10100011.01011100.10100011.01011100.10100011.0011100
Copy to filled bitmap
11011100.10100011.01011100.10100011.01011100.10100011.01011100.10100011.01011100.10100011.01011100.10100011.01011100.10100011.01011100.10100011.01011100.10100011.01011100.10100011.0011100
Copy to alternating bitmap
11011100.10100011.01011100.10100011.01011100.10100011.01011100.10100011.01011100.10100011.01011100.10100011.01011100.10100011.01011100.10100011.01011100.10100011.01011100.10100011.0011100
Copy to same bitmap
11011100.10100011.01011100.10100011.01011100.10100011.01011100.10100011.01011100.10100011.01011100.10100011.01011100.10100011.01011100.10100011.01011100.10100011.01011100.10100011.0011100
Test zero bit copies.
Copy 0 1 0
Copy to zeroed bitmap
00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.0000000
Copy to filled bitmap
11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.1111111
Copy to alternating bitmap
10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.0101010
Copy to same bitmap
10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.0111001
Copy 0 167 0
Copy to zeroed bitmap
00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000.0000000
Copy to filled bitmap
11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111.1111111
Copy to alternating bitmap
10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101.0101010
Copy to same bitmap
10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110.0111001
union(zeroes, pattern) = 10111001
union(ones, pattern) = 11111111
union(pattern, ones) = 11111111
union(pattern, zeroes) = 10111001
union(pattern, alternating) = 10111011
union(pattern, pattern) = 10111001
union(alternating, alternating) = 10101010
union(zeroes, pattern) = 10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110
union(ones, pattern) = 11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111
union(pattern, ones) = 11111111.11111111.11111111.11111111.11111111.11111111.11111111.11111111
union(pattern, zeroes) = 10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110
union(pattern, alternating) = 10111011.01010111.10111011.01010111.10111011.01010111.10111011.01010111
union(pattern, pattern) = 10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110
union(alternating, alternating) = 10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101
intersect(zeroes, pattern) = 00000000
intersect(ones, pattern) = 10111001
intersect(pattern, ones) = 10111001
intersect(pattern, zeroes) = 00000000
intersect(pattern, alternating) = 10101000
intersect(pattern, pattern) = 10111001
intersect(alternating, alternating) = 10101010
intersect(zeroes, pattern) = 00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000
intersect(ones, pattern) = 10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110
intersect(pattern, ones) = 10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110
intersect(pattern, zeroes) = 00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000
intersect(pattern, alternating) = 10101000.01000100.10101000.01000100.10101000.01000100.10101000.01000100
intersect(pattern, pattern) = 10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110
intersect(alternating, alternating) = 10101010.01010101.10101010.01010101.10101010.01010101.10101010.01010101
difference(zeroes, pattern) = 00000000
difference(ones, pattern) = 01000110
difference(pattern, ones) = 00000000
difference(pattern, zeroes) = 10111001
difference(pattern, alternating) = 00010001
difference(pattern, pattern) = 00000000
difference(alternating, alternating) = 00000000
difference(zeroes, pattern) = 00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000
difference(ones, pattern) = 01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001
difference(pattern, ones) = 00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000
difference(pattern, zeroes) = 10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110
difference(pattern, alternating) = 00010001.00000010.00010001.00000010.00010001.00000010.00010001.00000010
difference(pattern, pattern) = 00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000
difference(alternating, alternating) = 00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000
xor(zeroes, pattern) = 10111001
xor(ones, pattern) = 01000110
xor(pattern, ones) = 01000110
xor(pattern, zeroes) = 10111001
xor(pattern, alternating) = 00010011
xor(pattern, pattern) = 00000000
xor(alternating, alternating) = 00000000
xor(zeroes, pattern) = 10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110
xor(ones, pattern) = 01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001
xor(pattern, ones) = 01000110.10111001.01000110.10111001.01000110.10111001.01000110.10111001
xor(pattern, zeroes) = 10111001.01000110.10111001.01000110.10111001.01000110.10111001.01000110
xor(pattern, alternating) = 00010011.00010011.00010011.00010011.00010011.00010011.00010011.00010011
xor(pattern, pattern) = 00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000
xor(alternating, alternating) = 00000000.00000000.00000000.00000000.00000000.00000000.00000000.00000000
ordering(zeroes, pattern) = '<'
ordering(ones, pattern) = '>'
ordering(pattern, ones) = '<'
ordering(pattern, zeroes) = '>'
ordering(pattern, alternating) = '>'
ordering(pattern, pattern) = '='
ordering(alternating, alternating) = '='
ordering(zeroes, pattern) = '<'
ordering(ones, pattern) = '>'
ordering(pattern, ones) = '<'
ordering(pattern, zeroes) = '>'
ordering(pattern, alternating) = '>'
ordering(pattern, pattern) = '='
ordering(alternating, alternating) = '='
test_unify(zeroes, pattern) = no
test_unify(ones, pattern) = no
test_unify(pattern, ones) = no
test_unify(pattern, zeroes) = no
test_unify(pattern, alternating) = no
test_unify(pattern, pattern) = yes
test_unify(alternating, alternating) = yes
test_unify(zeroes, pattern) = no
test_unify(ones, pattern) = no
test_unify(pattern, ones) = no
test_unify(pattern, zeroes) = no
test_unify(pattern, alternating) = no
test_unify(pattern, pattern) = yes
test_unify(alternating, alternating) = yes
BMa = "<64:FFFFFFFFB725FFFF>".
BMb = "<47:FFF6B4BFFFFE>".
First read succeeded
Second read succeeded
First read succeeded
Second read succeeded
Found exception as expected: bitmap_error("bitmap.bit: index -1 is out of bounds [0 - 64).")
Found exception as expected: bitmap_error("bitmap.bit: index 64 is out of bounds [0 - 64).")
Found exception as expected: bitmap_error("bitmap.bit: index 73 is out of bounds [0 - 64).")
Found exception as expected: bitmap_error("copy_bits (source): 32 bits starting at bit -1 is out of bounds [0, 64).")
Found exception as expected: bitmap_error("copy_bits (source): 32 bits starting at bit 33 is out of bounds [0, 64).")
Found exception as expected: bitmap_error("copy_bits (destination): 32 bits starting at bit 33 is out of bounds [0, 64).")
Found exception as expected: bitmap_error("bitmap.bits: index -1 is out of bounds [0 - 64).")
Found exception as expected: bitmap_error("bitmap.bits: index 33 is out of bounds [0 - 64).")
Found exception as expected: bitmap_error("bitmap.bits: number of bits must be between 0 and `int.bits_per_int\'.")
Found exception as expected: bitmap_error("bitmap.bits: number of bits must be between 0 and `int.bits_per_int\'.")
Found exception as expected: bitmap_error("bitmap.bits: index 65 is out of bounds [0 - 64).")
Found exception as expected: bitmap_error("bitmap.bits: index -1 is out of bounds [0 - 64).")