Implement the function bitwise_and_between_numbers in a Python file named /app/solution.py. This function should compute the bitwise AND of all natural numbers within a given inclusive range from A to B.
This rewritten task requires EXACTLY two skills:
Skill 1: The original algorithmic skill to compute the bitwise AND across a range.
Skill 2: File I/O: read input from a file and write output to a file, integrated within the same solution module.
Requirements:
Functionality:
The function should take two integers, A and B, and return the result of the bitwise AND operation among all integers from A to B, inclusive of both endpoints.
In addition to the function, the module should perform file-based I/O with these specifics:
Read two integers A and B from a file located at /app/input.txt, with the integers separated by whitespace (space or newline). Confirm that A >= 0 and B >= A.
Compute the result by calling bitwise_and_between_numbers(A, B).
Write the resulting integer to a file located at /app/output.txt, as a single line containing only the integer.
The file I/O must occur only when the module is executed as a script (i.e., inside if __name__ == "__main__":) to avoid side effects during imports.
Ensure that tests importing the module do not rely on the presence of the files; the function itself must operate independently of the I/O.
Example:
If /app/input.txt contains:
text
5 7
then /app/output.txt should contain:
text
5
Edge Cases:
Consider cases where A equals B. For instance, if A = B = 3, the result should be 3.
You must ensure that the implementation is efficient and handles potential edge cases effectively. The module should be importable for testing (i.e., the I/O should not run on import) while also providing a convenient script-mode workflow via /app/input.txt and /app/output.txt when executed directly. Once implemented, please run tests to verify correctness.