Adam and Eve were given a time of probation. During this time, they could choose to obey God or choose their desires above
At that time, they had the ability to always choose rightly. They made the wrong choice
however and were confirmed in their decision (sin entered mankind.)
True, God knew that they would choose wrongly, for God knows all things (things past, things present, things that will be and things that could be.)
Even so, He gave mankind a free will; freedom of choice.
In setting a test, God showed that He wanted Adam to voluntarily choose to obey Him (Adam wasn't created as a robot.) Adam failed the test.