If you're wondering about the sensors, read up on robotics. Bump sensors, drop-off sensors (reflective sensors), range finders, and so on are pretty common. To detect whether it's hitting a lot of dirt, I believe it uses a piezoelectric sensor. The wheels have encoders so that it can determine how far each has gone and whether one (or both) is stuck. The sensors, I think, are the easy part.
As others have said, the Roomba does not map out the room. It estimates its size by taking random turns and making long runs, and it uses the longest run that it can make to estimate the size of the room, and uses that estimate to determine how long to continue cleaning. I would assume, without having checked, that it assumes that the room is roughly square and the longest run is approximately the diagonal across that square, or a little shorter. By determining the area and dividing by the width of the beater bar, it can estimate how long a perfect run would take to cover the floor. It should then multiply by some factor and use that to determine how long its run should be. This is all my guess based on my little research and observing how mine worked before the battery died. At least that's how I'd probably do it, and then run many many tests to determine what that factor should be and whether it works well. I would expect that you could do this with an Arduino. A Pi would certainly be overkill for this job.
If you wanted to create a map of the room, you would probably have to assume that it would be at least a bit inaccurate due to wheel slippage, moving obstacles, unknown impact angles, etc, but I wouldn't think that it would be too terribly difficult to try. I'd probably make a large grid to represent the room with low accuracy, start in the center of it, and measure how many grid spaces I can travel in one direction. When I hit something, I'd mark the grid that there's an obstacle there, turn, and try another run, marking the map each time I hit something. This would eventually create a rough map of the room. Problem is, if you get bumped just a fraction of a degree out of alignment, pretty soon the map will be useless, which is probably why Roomba doesn't bother. This would also require far more memory and processing power than a simplistic random model.