Commits

David Carr committed 5a9e716

tests: add one more tweak to make largestAndSmallestCitiesByState deterministic

Comments (0)

Files changed (3)

src/test/java/org/bitbucket/davidm24/mongodb/aggregate/DocumentationExamplesIT.java

                         .put("pop").sum("$pop")
                         .get()
                 )
-                .sort(newMap("pop", 1))
+                // Not quite what was in the documentation, since it was
+                // non-deterministic (dataset contains cities tied for pop)
+                .sort(newMap("pop", 1, "_id.city", 1))
                 .group(GroupBuilder.start()
                         .put("_id").to("$_id.state")
                         .put("biggestCity").last("$_id.city")

src/test/resources/org/bitbucket/davidm24/mongodb/aggregate/largestAndSmallestCitiesByStateTest.expected.command.json

-{ "aggregate" : "zipcodes" , "pipeline" : [ { "$group" : { "_id" : { "state" : "$state" , "city" : "$city"} , "pop" : { "$sum" : "$pop"}}} , { "$sort" : { "pop" : 1}} , { "$group" : { "_id" : "$_id.state" , "biggestCity" : { "$last" : "$_id.city"} , "biggestPop" : { "$last" : "$pop"} , "smallestCity" : { "$first" : "$_id.city"} , "smallestPop" : { "$first" : "$pop"}}} , { "$project" : { "_id" : 0 , "state" : "$_id" , "biggestCity" : { "name" : "$biggestCity" , "pop" : "$biggestPop"} , "smallestCity" : { "name" : "$smallestCity" , "pop" : "$smallestPop"}}} , { "$sort" : { "state" : 1}}]}
+{ "aggregate" : "zipcodes" , "pipeline" : [ { "$group" : { "_id" : { "state" : "$state" , "city" : "$city"} , "pop" : { "$sum" : "$pop"}}} , { "$sort" : { "pop" : 1 , "_id.city" : 1}} , { "$group" : { "_id" : "$_id.state" , "biggestCity" : { "$last" : "$_id.city"} , "biggestPop" : { "$last" : "$pop"} , "smallestCity" : { "$first" : "$_id.city"} , "smallestPop" : { "$first" : "$pop"}}} , { "$project" : { "_id" : 0 , "state" : "$_id" , "biggestCity" : { "name" : "$biggestCity" , "pop" : "$biggestPop"} , "smallestCity" : { "name" : "$smallestCity" , "pop" : "$smallestPop"}}} , { "$sort" : { "state" : 1}}]}

src/test/resources/org/bitbucket/davidm24/mongodb/aggregate/largestAndSmallestCitiesByStateTest.expected.results.json

-[ { "biggestCity" : { "name" : "ANCHORAGE" , "pop" : 183987} , "smallestCity" : { "name" : "NAKNEK" , "pop" : 0} , "state" : "AK"} , { "biggestCity" : { "name" : "BIRMINGHAM" , "pop" : 242606} , "smallestCity" : { "name" : "ALLEN" , "pop" : 0} , "state" : "AL"} , { "biggestCity" : { "name" : "LITTLE ROCK" , "pop" : 192895} , "smallestCity" : { "name" : "TOMATO" , "pop" : 0} , "state" : "AR"} , { "biggestCity" : { "name" : "PHOENIX" , "pop" : 890853} , "smallestCity" : { "name" : "HUALAPAI" , "pop" : 2} , "state" : "AZ"} , { "biggestCity" : { "name" : "LOS ANGELES" , "pop" : 2102295} , "smallestCity" : { "name" : "ALLEGHANY" , "pop" : 0} , "state" : "CA"} , { "biggestCity" : { "name" : "DENVER" , "pop" : 451182} , "smallestCity" : { "name" : "CHEYENNE MTN AFB" , "pop" : 0} , "state" : "CO"} , { "biggestCity" : { "name" : "BRIDGEPORT" , "pop" : 141638} , "smallestCity" : { "name" : "EAST KILLINGLY" , "pop" : 25} , "state" : "CT"} , { "biggestCity" : { "name" : "WASHINGTON" , "pop" : 606879} , "smallestCity" : { "name" : "PENTAGON" , "pop" : 21} , "state" : "DC"} , { "biggestCity" : { "name" : "NEWARK" , "pop" : 111674} , "smallestCity" : { "name" : "BETHEL" , "pop" : 108} , "state" : "DE"} , { "biggestCity" : { "name" : "MIAMI" , "pop" : 825232} , "smallestCity" : { "name" : "CECIL FIELD NAS" , "pop" : 0} , "state" : "FL"} , { "biggestCity" : { "name" : "ATLANTA" , "pop" : 609591} , "smallestCity" : { "name" : "FORT STEWART" , "pop" : 0} , "state" : "GA"} , { "biggestCity" : { "name" : "HONOLULU" , "pop" : 396643} , "smallestCity" : { "name" : "NINOLE" , "pop" : 0} , "state" : "HI"} , { "biggestCity" : { "name" : "DES MOINES" , "pop" : 148155} , "smallestCity" : { "name" : "DOUDS" , "pop" : 15} , "state" : "IA"} , { "biggestCity" : { "name" : "BOISE" , "pop" : 165522} , "smallestCity" : { "name" : "KEUTERVILLE" , "pop" : 0} , "state" : "ID"} , { "biggestCity" : { "name" : "CHICAGO" , "pop" : 2452177} , "smallestCity" : { "name" : "ANCONA" , "pop" : 38} , "state" : "IL"} , { "biggestCity" : { "name" : "INDIANAPOLIS" , "pop" : 348868} , "smallestCity" : { "name" : "47559" , "pop" : 23} , "state" : "IN"} , { "biggestCity" : { "name" : "WICHITA" , "pop" : 295115} , "smallestCity" : { "name" : "ARNOLD" , "pop" : 0} , "state" : "KS"} , { "biggestCity" : { "name" : "LOUISVILLE" , "pop" : 288058} , "smallestCity" : { "name" : "BIG LAUREL" , "pop" : 0} , "state" : "KY"} , { "biggestCity" : { "name" : "NEW ORLEANS" , "pop" : 496937} , "smallestCity" : { "name" : "FORDOCHE" , "pop" : 0} , "state" : "LA"} , { "biggestCity" : { "name" : "WORCESTER" , "pop" : 169856} , "smallestCity" : { "name" : "BUCKLAND" , "pop" : 16} , "state" : "MA"} , { "biggestCity" : { "name" : "BALTIMORE" , "pop" : 733081} , "smallestCity" : { "name" : "ANNAPOLIS JUNCTI" , "pop" : 32} , "state" : "MD"} , { "biggestCity" : { "name" : "PORTLAND" , "pop" : 63268} , "smallestCity" : { "name" : "BUSTINS ISLAND" , "pop" : 0} , "state" : "ME"} , { "biggestCity" : { "name" : "DETROIT" , "pop" : 963243} , "smallestCity" : { "name" : "LELAND" , "pop" : 0} , "state" : "MI"} , { "biggestCity" : { "name" : "MINNEAPOLIS" , "pop" : 344719} , "smallestCity" : { "name" : "JOHNSON" , "pop" : 12} , "state" : "MN"} , { "biggestCity" : { "name" : "SAINT LOUIS" , "pop" : 397802} , "smallestCity" : { "name" : "BENDAVIS" , "pop" : 44} , "state" : "MO"} , { "biggestCity" : { "name" : "JACKSON" , "pop" : 204788} , "smallestCity" : { "name" : "CHUNKY" , "pop" : 79} , "state" : "MS"} , { "biggestCity" : { "name" : "BILLINGS" , "pop" : 78805} , "smallestCity" : { "name" : "HOMESTEAD" , "pop" : 7} , "state" : "MT"} , { "biggestCity" : { "name" : "CHARLOTTE" , "pop" : 465833} , "smallestCity" : { "name" : "GLOUCESTER" , "pop" : 0} , "state" : "NC"} , { "biggestCity" : { "name" : "GRAND FORKS" , "pop" : 59527} , "smallestCity" : { "name" : "TROTTERS" , "pop" : 12} , "state" : "ND"} , { "biggestCity" : { "name" : "OMAHA" , "pop" : 358930} , "smallestCity" : { "name" : "LAKESIDE" , "pop" : 5} , "state" : "NE"} , { "biggestCity" : { "name" : "MANCHESTER" , "pop" : 106452} , "smallestCity" : { "name" : "WEST NOTTINGHAM" , "pop" : 27} , "state" : "NH"} , { "biggestCity" : { "name" : "NEWARK" , "pop" : 275572} , "smallestCity" : { "name" : "IMLAYSTOWN" , "pop" : 17} , "state" : "NJ"} , { "biggestCity" : { "name" : "ALBUQUERQUE" , "pop" : 449584} , "smallestCity" : { "name" : "REGINA" , "pop" : 0} , "state" : "NM"} , { "biggestCity" : { "name" : "LAS VEGAS" , "pop" : 597557} , "smallestCity" : { "name" : "TUSCARORA" , "pop" : 1} , "state" : "NV"} , { "biggestCity" : { "name" : "BROOKLYN" , "pop" : 2300504} , "smallestCity" : { "name" : "EAST SPRINGFIELD" , "pop" : 0} , "state" : "NY"} , { "biggestCity" : { "name" : "CLEVELAND" , "pop" : 536759} , "smallestCity" : { "name" : "ISLE SAINT GEORG" , "pop" : 38} , "state" : "OH"} , { "biggestCity" : { "name" : "TULSA" , "pop" : 389072} , "smallestCity" : { "name" : "SOUTHARD" , "pop" : 8} , "state" : "OK"} , { "biggestCity" : { "name" : "PORTLAND" , "pop" : 518543} , "smallestCity" : { "name" : "LYONS" , "pop" : 0} , "state" : "OR"} , { "biggestCity" : { "name" : "PHILADELPHIA" , "pop" : 1610956} , "smallestCity" : { "name" : "HAMILTON" , "pop" : 0} , "state" : "PA"} , { "biggestCity" : { "name" : "CRANSTON" , "pop" : 176404} , "smallestCity" : { "name" : "CLAYVILLE" , "pop" : 45} , "state" : "RI"} , { "biggestCity" : { "name" : "COLUMBIA" , "pop" : 269521} , "smallestCity" : { "name" : "QUINBY" , "pop" : 0} , "state" : "SC"} , { "biggestCity" : { "name" : "SIOUX FALLS" , "pop" : 102046} , "smallestCity" : { "name" : "ZEONA" , "pop" : 8} , "state" : "SD"} , { "biggestCity" : { "name" : "MEMPHIS" , "pop" : 632837} , "smallestCity" : { "name" : "ALLRED" , "pop" : 2} , "state" : "TN"} , { "biggestCity" : { "name" : "HOUSTON" , "pop" : 2095918} , "smallestCity" : { "name" : "ECLETO" , "pop" : 0} , "state" : "TX"} , { "biggestCity" : { "name" : "SALT LAKE CITY" , "pop" : 186346} , "smallestCity" : { "name" : "MODENA" , "pop" : 9} , "state" : "UT"} , { "biggestCity" : { "name" : "VIRGINIA BEACH" , "pop" : 385080} , "smallestCity" : { "name" : "WALLOPS ISLAND" , "pop" : 0} , "state" : "VA"} , { "biggestCity" : { "name" : "BURLINGTON" , "pop" : 39127} , "smallestCity" : { "name" : "UNIV OF VERMONT" , "pop" : 0} , "state" : "VT"} , { "biggestCity" : { "name" : "SEATTLE" , "pop" : 520096} , "smallestCity" : { "name" : "BENGE" , "pop" : 2} , "state" : "WA"} , { "biggestCity" : { "name" : "MILWAUKEE" , "pop" : 597324} , "smallestCity" : { "name" : "CLAM LAKE" , "pop" : 2} , "state" : "WI"} , { "biggestCity" : { "name" : "HUNTINGTON" , "pop" : 75343} , "smallestCity" : { "name" : "MOUNT CARBON" , "pop" : 0} , "state" : "WV"} , { "biggestCity" : { "name" : "CHEYENNE" , "pop" : 70185} , "smallestCity" : { "name" : "LOST SPRINGS" , "pop" : 6} , "state" : "WY"}]
+[ { "biggestCity" : { "name" : "ANCHORAGE" , "pop" : 183987} , "smallestCity" : { "name" : "CHEVAK" , "pop" : 0} , "state" : "AK"} , { "biggestCity" : { "name" : "BIRMINGHAM" , "pop" : 242606} , "smallestCity" : { "name" : "ALLEN" , "pop" : 0} , "state" : "AL"} , { "biggestCity" : { "name" : "LITTLE ROCK" , "pop" : 192895} , "smallestCity" : { "name" : "TOMATO" , "pop" : 0} , "state" : "AR"} , { "biggestCity" : { "name" : "PHOENIX" , "pop" : 890853} , "smallestCity" : { "name" : "HUALAPAI" , "pop" : 2} , "state" : "AZ"} , { "biggestCity" : { "name" : "LOS ANGELES" , "pop" : 2102295} , "smallestCity" : { "name" : "ALLEGHANY" , "pop" : 0} , "state" : "CA"} , { "biggestCity" : { "name" : "DENVER" , "pop" : 451182} , "smallestCity" : { "name" : "CHEYENNE MTN AFB" , "pop" : 0} , "state" : "CO"} , { "biggestCity" : { "name" : "BRIDGEPORT" , "pop" : 141638} , "smallestCity" : { "name" : "EAST KILLINGLY" , "pop" : 25} , "state" : "CT"} , { "biggestCity" : { "name" : "WASHINGTON" , "pop" : 606879} , "smallestCity" : { "name" : "PENTAGON" , "pop" : 21} , "state" : "DC"} , { "biggestCity" : { "name" : "NEWARK" , "pop" : 111674} , "smallestCity" : { "name" : "BETHEL" , "pop" : 108} , "state" : "DE"} , { "biggestCity" : { "name" : "MIAMI" , "pop" : 825232} , "smallestCity" : { "name" : "CECIL FIELD NAS" , "pop" : 0} , "state" : "FL"} , { "biggestCity" : { "name" : "ATLANTA" , "pop" : 609591} , "smallestCity" : { "name" : "FORT STEWART" , "pop" : 0} , "state" : "GA"} , { "biggestCity" : { "name" : "HONOLULU" , "pop" : 396643} , "smallestCity" : { "name" : "NINOLE" , "pop" : 0} , "state" : "HI"} , { "biggestCity" : { "name" : "DES MOINES" , "pop" : 148155} , "smallestCity" : { "name" : "DOUDS" , "pop" : 15} , "state" : "IA"} , { "biggestCity" : { "name" : "BOISE" , "pop" : 165522} , "smallestCity" : { "name" : "KEUTERVILLE" , "pop" : 0} , "state" : "ID"} , { "biggestCity" : { "name" : "CHICAGO" , "pop" : 2452177} , "smallestCity" : { "name" : "ANCONA" , "pop" : 38} , "state" : "IL"} , { "biggestCity" : { "name" : "INDIANAPOLIS" , "pop" : 348868} , "smallestCity" : { "name" : "47559" , "pop" : 23} , "state" : "IN"} , { "biggestCity" : { "name" : "WICHITA" , "pop" : 295115} , "smallestCity" : { "name" : "ARNOLD" , "pop" : 0} , "state" : "KS"} , { "biggestCity" : { "name" : "LOUISVILLE" , "pop" : 288058} , "smallestCity" : { "name" : "BIG LAUREL" , "pop" : 0} , "state" : "KY"} , { "biggestCity" : { "name" : "NEW ORLEANS" , "pop" : 496937} , "smallestCity" : { "name" : "FORDOCHE" , "pop" : 0} , "state" : "LA"} , { "biggestCity" : { "name" : "WORCESTER" , "pop" : 169856} , "smallestCity" : { "name" : "BUCKLAND" , "pop" : 16} , "state" : "MA"} , { "biggestCity" : { "name" : "BALTIMORE" , "pop" : 733081} , "smallestCity" : { "name" : "ANNAPOLIS JUNCTI" , "pop" : 32} , "state" : "MD"} , { "biggestCity" : { "name" : "PORTLAND" , "pop" : 63268} , "smallestCity" : { "name" : "BUSTINS ISLAND" , "pop" : 0} , "state" : "ME"} , { "biggestCity" : { "name" : "DETROIT" , "pop" : 963243} , "smallestCity" : { "name" : "LELAND" , "pop" : 0} , "state" : "MI"} , { "biggestCity" : { "name" : "MINNEAPOLIS" , "pop" : 344719} , "smallestCity" : { "name" : "JOHNSON" , "pop" : 12} , "state" : "MN"} , { "biggestCity" : { "name" : "SAINT LOUIS" , "pop" : 397802} , "smallestCity" : { "name" : "BENDAVIS" , "pop" : 44} , "state" : "MO"} , { "biggestCity" : { "name" : "JACKSON" , "pop" : 204788} , "smallestCity" : { "name" : "CHUNKY" , "pop" : 79} , "state" : "MS"} , { "biggestCity" : { "name" : "BILLINGS" , "pop" : 78805} , "smallestCity" : { "name" : "HOMESTEAD" , "pop" : 7} , "state" : "MT"} , { "biggestCity" : { "name" : "CHARLOTTE" , "pop" : 465833} , "smallestCity" : { "name" : "GLOUCESTER" , "pop" : 0} , "state" : "NC"} , { "biggestCity" : { "name" : "GRAND FORKS" , "pop" : 59527} , "smallestCity" : { "name" : "TROTTERS" , "pop" : 12} , "state" : "ND"} , { "biggestCity" : { "name" : "OMAHA" , "pop" : 358930} , "smallestCity" : { "name" : "LAKESIDE" , "pop" : 5} , "state" : "NE"} , { "biggestCity" : { "name" : "MANCHESTER" , "pop" : 106452} , "smallestCity" : { "name" : "WEST NOTTINGHAM" , "pop" : 27} , "state" : "NH"} , { "biggestCity" : { "name" : "NEWARK" , "pop" : 275572} , "smallestCity" : { "name" : "IMLAYSTOWN" , "pop" : 17} , "state" : "NJ"} , { "biggestCity" : { "name" : "ALBUQUERQUE" , "pop" : 449584} , "smallestCity" : { "name" : "ALGODONES" , "pop" : 0} , "state" : "NM"} , { "biggestCity" : { "name" : "LAS VEGAS" , "pop" : 597557} , "smallestCity" : { "name" : "TUSCARORA" , "pop" : 1} , "state" : "NV"} , { "biggestCity" : { "name" : "BROOKLYN" , "pop" : 2300504} , "smallestCity" : { "name" : "CHILDWOLD" , "pop" : 0} , "state" : "NY"} , { "biggestCity" : { "name" : "CLEVELAND" , "pop" : 536759} , "smallestCity" : { "name" : "ISLE SAINT GEORG" , "pop" : 38} , "state" : "OH"} , { "biggestCity" : { "name" : "TULSA" , "pop" : 389072} , "smallestCity" : { "name" : "SOUTHARD" , "pop" : 8} , "state" : "OK"} , { "biggestCity" : { "name" : "PORTLAND" , "pop" : 518543} , "smallestCity" : { "name" : "KENT" , "pop" : 0} , "state" : "OR"} , { "biggestCity" : { "name" : "PHILADELPHIA" , "pop" : 1610956} , "smallestCity" : { "name" : "HAMILTON" , "pop" : 0} , "state" : "PA"} , { "biggestCity" : { "name" : "CRANSTON" , "pop" : 176404} , "smallestCity" : { "name" : "CLAYVILLE" , "pop" : 45} , "state" : "RI"} , { "biggestCity" : { "name" : "COLUMBIA" , "pop" : 269521} , "smallestCity" : { "name" : "QUINBY" , "pop" : 0} , "state" : "SC"} , { "biggestCity" : { "name" : "SIOUX FALLS" , "pop" : 102046} , "smallestCity" : { "name" : "ZEONA" , "pop" : 8} , "state" : "SD"} , { "biggestCity" : { "name" : "MEMPHIS" , "pop" : 632837} , "smallestCity" : { "name" : "ALLRED" , "pop" : 2} , "state" : "TN"} , { "biggestCity" : { "name" : "HOUSTON" , "pop" : 2095918} , "smallestCity" : { "name" : "ECLETO" , "pop" : 0} , "state" : "TX"} , { "biggestCity" : { "name" : "SALT LAKE CITY" , "pop" : 186346} , "smallestCity" : { "name" : "MODENA" , "pop" : 9} , "state" : "UT"} , { "biggestCity" : { "name" : "VIRGINIA BEACH" , "pop" : 385080} , "smallestCity" : { "name" : "WALLOPS ISLAND" , "pop" : 0} , "state" : "VA"} , { "biggestCity" : { "name" : "BURLINGTON" , "pop" : 39127} , "smallestCity" : { "name" : "UNIV OF VERMONT" , "pop" : 0} , "state" : "VT"} , { "biggestCity" : { "name" : "SEATTLE" , "pop" : 520096} , "smallestCity" : { "name" : "BENGE" , "pop" : 2} , "state" : "WA"} , { "biggestCity" : { "name" : "MILWAUKEE" , "pop" : 597324} , "smallestCity" : { "name" : "CLAM LAKE" , "pop" : 2} , "state" : "WI"} , { "biggestCity" : { "name" : "HUNTINGTON" , "pop" : 75343} , "smallestCity" : { "name" : "MOUNT CARBON" , "pop" : 0} , "state" : "WV"} , { "biggestCity" : { "name" : "CHEYENNE" , "pop" : 70185} , "smallestCity" : { "name" : "LOST SPRINGS" , "pop" : 6} , "state" : "WY"}]