@@ -172,6 +172,54 @@ void testHarmonicMeanWithLinkedList() {
172172 assertEquals (expected , Means .harmonic (numbers ), EPSILON );
173173 }
174174
175+ // ========== Quadratic Mean Tests ==========
176+
177+ @ Test
178+ void testQuadraticMeanThrowsExceptionForEmptyList () {
179+ List <Double > numbers = new ArrayList <>();
180+ IllegalArgumentException exception = assertThrows (IllegalArgumentException .class , () -> Means .quadratic (numbers ));
181+ assertTrue (exception .getMessage ().contains ("Empty list" ));
182+ }
183+
184+ @ Test
185+ void testHarmonicMeanTwoNumbers () {
186+ List <Double > numbers = Arrays .asList (2.0 , 6.0 );
187+ double expected = Math .sqrt (20.0 );
188+ assertEquals (expected , Means .quadratic (numbers ), EPSILON );
189+ }
190+
191+ @ Test
192+ void testHarmonicMeanTwoNumbers () {
193+ List <Double > numbers = Arrays .asList (1.0 , 7.0 );
194+ assertEquals (5.0 , Means .quadratic (numbers ), EPSILON );
195+ }
196+
197+ @ Test
198+ void testQuadraticMeanWithLinkedList () {
199+ LinkedList <Double > numbers = new LinkedList <>(Arrays .asList (3.0 , 6.0 , 9.0 ));
200+ double expected = Math .sqrt (42.0 );
201+ assertEquals (expected , Means .quadratic (numbers ), EPSILON );
202+ }
203+
204+ @ Test
205+ void testQuadraticMeanWithLinkedList () {
206+ LinkedList <Double > numbers = new LinkedList <>(Arrays .asList (1.0 , 2.0 , 4.0 ));
207+ double expected = Math .sqrt (7.0 );
208+ assertEquals (expected , Means .quadratic (numbers ), EPSILON );
209+ }
210+
211+ @ Test
212+ void testQuadraticMeanWithLinkedList () {
213+ LinkedList <Double > numbers = new LinkedList <>(Arrays .asList (1.0 , 5.0 , 11.0 ));
214+ assertEquals (7.0 , Means .quadratic (numbers ), EPSILON );
215+ }
216+
217+ @ Test
218+ void testQuadraticMeanWithLinkedList () {
219+ LinkedList <Double > numbers = new LinkedList <>(Arrays .asList (5.0 , 5.0 , 5.0 ));
220+ assertEquals (5.0 , Means .quadratic (numbers ), EPSILON );
221+ }
222+
175223 // ========== Additional Edge Case Tests ==========
176224
177225 @ Test
@@ -198,21 +246,25 @@ void testAllMeansConsistencyForIdenticalValues() {
198246 double arithmetic = Means .arithmetic (numbers );
199247 double geometric = Means .geometric (numbers );
200248 double harmonic = Means .harmonic (numbers );
249+ double quadratic = Means .quadratic (numbers );
201250
202251 assertEquals (7.5 , arithmetic , EPSILON );
203252 assertEquals (7.5 , geometric , EPSILON );
204253 assertEquals (7.5 , harmonic , EPSILON );
254+ assertEquals (7.5 , quadratic , EPSILON );
205255 }
206256
207257 @ Test
208258 void testMeansRelationship () {
209- // For positive numbers, harmonic mean ≤ geometric mean ≤ arithmetic mean
259+ // For positive numbers, harmonic mean ≤ geometric mean ≤ arithmetic mean ≤ quadratic mean
210260 List <Double > numbers = Arrays .asList (2.0 , 4.0 , 8.0 );
211261 double arithmetic = Means .arithmetic (numbers );
212262 double geometric = Means .geometric (numbers );
213263 double harmonic = Means .harmonic (numbers );
264+ double quadratic = Means .quadratic (numbers );
214265
215266 assertTrue (harmonic <= geometric , "Harmonic mean should be ≤ geometric mean" );
216267 assertTrue (geometric <= arithmetic , "Geometric mean should be ≤ arithmetic mean" );
268+ assertTrue (arithmetic <= quadratic , "Arithmetic mean should be ≤ quadratic mean" );
217269 }
218270}
0 commit comments