The electric potential energy of a test charge in a uniform eclectic field can be generalized to any electric field produced by static charge distribution. Consider a positive test charge in an electric field produced by another static positive charge. If the test charge is moved away from the static charge, then the electric field does the positive work on the test charge, and the electric potential energy of the test charge decreases as it moves away from the static charge. Here the electric field is not constant as the test charge moves; therefore, work done is expressed as integral to the force times the displacement of the test charge in the radial direction. The work depends only on the endpoints and not on the path taken by the test charge. If the test charge moves in some arbitrary direction, which is not radial, the work done is defined by the start and end position of the test charge.
The potential energy is defined as zero at an infinite separation of two charges as there will be little interaction between them at infinite separation. The electrical potential energy is positive if the two charges are of the same type, either positive or negative, and negative if the two charges are of opposite types. Depending on the relative types of charges, work will be done on the system, or the system will do work on text charges. If positive work is done on the system (pushing the charges closer), then the system's energy should increase. If two positive or negative charges are brought closer, positive work will be done on the system, raising their potential energy. Since potential energy is inversely proportional to the separation of two charges, the potential energy goes up when the distance decreases between two positive or two negative charges.
On the other hand, if a positive and a negative charge are brought closer, negative work will be done on the system, which means that energy is taken away from the system. This reduces the potential energy. Since potential energy is negative in the case of a positive and a negative charge pair, the decrease in separation between two opposite charges makes the potential energy more negative, which is the same as a reduction in potential energy.