Well thats a good example but its not a one way function afterall, because although you cant know for sure what was the x, you have the possibilities, in this case only 2, i guess with harder problems this number increases and if from 2 possibilities we jump to millions then its pretty much impossible to know all of them not taking in count how hard it would be to go in reverse, of course in your example is not hard.
Its easier to understand with an easy example. The definition of one way function is just that, its only a function in one direction and there is no reverse function. There might be an algorithm to reverse the operation and it might not be important to get the exact same input either. One might not care whether one gets -2 or 2 as long as its a possible input. Similar with bitcoin mining. Any input that results in the needed hash value is good for the miners, it means they just found a valid block and thus get the blockreward.
SHA256 is mostly important for mining and its done twice in order to add a layer of difficulty even if SHA256 should be vulnerable. Its more likely that there are shortcuts found over time than that its just broken (as in: can be reversed) one day. While broken SHA256 would certainly be a big problem for bitcoin it would also be a big problem for many other applications.
In terms of private keys an attacker would need to break not only SHA256, but also elliptic curves and RIPEMD160. The private key can only be calculated from the public key if ECDSA[1] is broken, which again would be a huge problem for many other applications besides bitcoin. But even if ECDSA was broken, you can only get the public key from a bitcoin address if you also break SHA256 and RIPEMD160 as both are needed to reverse the calculations of an address[2]. Keep in mind thought that the public key is known to the blockchain if you spend "from"[3] the address in question. This is why using a new address every time adds a (tiny little) bit of security. SHA256 is also considered to be quantum secure while ECDSA is not.
[1] https://en.bitcoin.it/wiki/Elliptic_Curve_Digital_Signature_Algorithm
[2] https://en.bitcoin.it/wiki/Technical_background_of_version_1_Bitcoin_addresses
[3] bitcoins are not actually spend from addresses, but rather refer to another transaction.