{"action":"created","issue":{"url":"https://api.github.com/repos/rickynils/scalacheck/issues/247","repository_url":"https://api.github.com/repos/rickynils/scalacheck","labels_url":"https://api.github.com/repos/rickynils/scalacheck/issues/247/labels{/name}","comments_url":"https://api.github.com/repos/rickynils/scalacheck/issues/247/comments","events_url":"https://api.github.com/repos/rickynils/scalacheck/issues/247/events","html_url":"https://github.com/rickynils/scalacheck/issues/247","id":161696767,"number":247,"title":"Arbitrary instance for Char","user":{"login":"lunaryorn","id":224922,"avatar_url":"https://avatars.githubusercontent.com/u/224922?v=3","gravatar_id":"","url":"https://api.github.com/users/lunaryorn","html_url":"https://github.com/lunaryorn","followers_url":"https://api.github.com/users/lunaryorn/followers","following_url":"https://api.github.com/users/lunaryorn/following{/other_user}","gists_url":"https://api.github.com/users/lunaryorn/gists{/gist_id}","starred_url":"https://api.github.com/users/lunaryorn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lunaryorn/subscriptions","organizations_url":"https://api.github.com/users/lunaryorn/orgs","repos_url":"https://api.github.com/users/lunaryorn/repos","events_url":"https://api.github.com/users/lunaryorn/events{/privacy}","received_events_url":"https://api.github.com/users/lunaryorn/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-06-22T14:22:46Z","updated_at":"2016-07-07T09:06:31Z","closed_at":null,"body":"I'd like to generate non-BMP strings with scalacheck, essentially to check whether our code base copes with emojis and all sorts of other strange unicode chars users might enter on their phones.\r\n\r\nI tried to figure out whether scalacheck might already have be covered here, and came across the current Arbitrary[Char] instance which looks rather… sophisticated:\r\n\r\n```scala\r\n /** Arbitrary instance of Char */\r\n  implicit lazy val arbChar: Arbitrary[Char] = Arbitrary(\r\n    Gen.frequency(\r\n      (0xD800-Char.MinValue, Gen.choose[Char](Char.MinValue,0xD800-1)),\r\n      (Char.MaxValue-0xDFFF, Gen.choose[Char](0xDFFF+1,Char.MaxValue))\r\n    )\r\n```\r\n\r\nWhat's the reason for \"Gen.frequency\" and the exclusion of some char ranges?  \r\n\r\nThe instance used to be `Gen.choose(Char.MinValue, Char.MaxValue)`, but a long time ago the current instance was introduced in c0f3c0d42067807706b54bbc95a9eeed66182b46.  Unfortunately the commit message is very, uhm, \"brief\", and it's not Github's issue #78 it refers to obviously.\r\n\r\nCan anyone shed a light on this rather peculiar instance?  Am I missing something very obvious?"},"comment":{"url":"https://api.github.com/repos/rickynils/scalacheck/issues/comments/231023862","html_url":"https://github.com/rickynils/scalacheck/issues/247#issuecomment-231023862","issue_url":"https://api.github.com/repos/rickynils/scalacheck/issues/247","id":231023862,"user":{"login":"phipsgabler","id":7878215,"avatar_url":"https://avatars.githubusercontent.com/u/7878215?v=3","gravatar_id":"","url":"https://api.github.com/users/phipsgabler","html_url":"https://github.com/phipsgabler","followers_url":"https://api.github.com/users/phipsgabler/followers","following_url":"https://api.github.com/users/phipsgabler/following{/other_user}","gists_url":"https://api.github.com/users/phipsgabler/gists{/gist_id}","starred_url":"https://api.github.com/users/phipsgabler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/phipsgabler/subscriptions","organizations_url":"https://api.github.com/users/phipsgabler/orgs","repos_url":"https://api.github.com/users/phipsgabler/repos","events_url":"https://api.github.com/users/phipsgabler/events{/privacy}","received_events_url":"https://api.github.com/users/phipsgabler/received_events","type":"User","site_admin":false},"created_at":"2016-07-07T09:06:31Z","updated_at":"2016-07-07T09:06:31Z","body":"I'm not a developer of this, but the range 0xD800 to 0xDFFF are the [surrogate characters](https://en.wikipedia.org/wiki/Universal_Character_Set_characters#Surrogates), used to encode chars outside of the BMP. Since these only make sense in pairs (high + low), generating them individually seems of no use (according to the link, \"isolated surrogate code points have no general interpretation\").\r\n\r\nThe `Gen.frequency` is needed to make the distribution uniform; with just a `Gen.oneOf` of the two blocks, the generated values would be right skewed, so they are weighed by their lengths to compensate that.\r\n\r\nIn order to generate stuff outside the BMP, I suppose you have to write your own generator. Or probably, there already exists such a thing somewhere..."}}
{"actor":{"display_login":"phipsgabler"}}