Prefacing a request with the expression “I was wondering if...”, as in “I was wondering if you could lend me your tire gauge,” is a polite and deferential way to ask for a favor from somebody—more polite and deferential than just saying “Please lend me your tire gauge” and much less demanding than “Could you lend me your tire gauge?”
In contrast, when someone prefaces a statement with “I am wondering if…”, as in “I am wondering if that guy will lend me his tire gauge,” it’s normally when talking aloud to himself or herself—whether alone or in the presence of another person. It’s a way of sizing up the possibility of a particular request being granted before that request is actually made to the person concerned. It’s flat-out wrong and improper to address a request prefaced by “I am wondering if…” directly to the person requested; for that purpose, the past-tense preface “I was wondering if...” should be used.
For the second situation you presented—when a classmate approaches you and asks you if you are prepared for the exam in your class—you have correctly chosen “I forgot we HAVE an exam today” instead “I forgot we HAD an exam today.” This is because, as you have correctly surmised, the exam has not yet taken place; if the exam has already taken place, however, the latter version would apply: “I forgot we HAD an exam today.”
For the sentence pairs you presented, the sentences set in red text below are the correct usage:
“I realized I liked you.” (Improper form that should be avoided. It can be perceived by the person addressed as an insult.)
“I realized I like you.” (Correct as a declaration being said now.)
“She said she was pregnant.” (Correct as reported speech for something declared in the past.)
“She said she is pregnant.” (Correct as reported speech for something being said now.)
“I didn’t know your name was Mary.” (Correct as declaration of a supposition made in the past.)
“I didn’t know your name is Mary.” (Correct as a declaration of a supposition being made now.)
“I told her that I was leaving for the US in June.” (Correct as a declaration of something said sometime in the past, and it’s already past June.)
“I told her that I am leaving for the US in June.” (Correct as a declaration of something said sometime in the past, and it’s not yet past June.)